fix(sessions): default-account resume command clears an inherited CLAUDE_CONFIG_DIR

Merged
GR
4d ago
+170-24

Fixes #172.

What

The resume command CodeV builds for a session of the default (anchor) account now clears CLAUDE_CONFIG_DIR for that one process:

Session belongs toBeforeAfter
default accountcd '<project>' && command claude --resume <id>cd '<project>' && env -u CLAUDE_CONFIG_DIR claude --resume <id>
another accountcd '<project>' && CLAUDE_CONFIG_DIR='<dir>' command claude --resume <id>unchanged

Why

The old default-account command set nothing, so it used whatever the shell had. In a shell that already has another account's CLAUDE_CONFIG_DIR — most often a shell inside that account's Claude Code session, where codev session resume or a pasted "Copy resume command" is run — Claude Code looked for the session under the other account and printed No conversation found with session ID: …. The command format is older than the codev session CLI (1.0.96), but the CLI made the case easy to reach.

Why this form

  • It is already in use on the same paths. The new-session launcher sends env -u CLAUDE_CONFIG_DIR claude for the default account through the same terminal code (iTerm2, Terminal.app, Ghostty, cmux), and the generated claude shell function launches the default account the same way.
  • env runs the binary from PATH, so it skips the claude shell function just as command claude did. The account is already decided; the function must not re-route it.
  • The new string adds no quote, backslash, $ or backtick, so the places that paste it into an AppleScript string or a /bin/sh double-quoted argument need no new escaping.
  • Not an explicit CLAUDE_CONFIG_DIR='<home>/.claude': the multi-account design doc (§3.4) records that Claude Code then reads a different state file and shows the account as logged out. The default account is "variable unset", so the command unsets it.
  • Not a warning in the CLI only: a pasted command would still fail.

The change is one function (formatResumeCommand in src/cli/session-identity.ts). Everything that shows or runs a resume command goes through it: the four terminal launchers, the copy action, the copy menu and details view, codev session show / self / resume, and the saved-list bulk open.

One behaviour to know: when the account of a session is unknown (it is in no account's history and no label was passed), the command used to inherit the shell's value and now always targets the default account. Inside the app this changes nothing, because the app's environment has no such variable.

Verification

  • npx tsc --noEmit: 0 errors. yarn test: 18 files, 387 tests pass.

  • New end-to-end test of the shell path, in zsh and in bash: the real CLI output, the real generated accounts.sh, codev session resume <id> run in a shell that exports another account's CLAUDE_CONFIG_DIR, with a stub claude on PATH that records what it sees. The default-account session must reach the stub with the variable unset; a session of another account must reach it with that account's folder. The registry's global default is a third account, so a command that wrongly went through the claude function would be caught too.

  • Mutation check: restoring the old command turns 7 tests red (the shell tests receive the inherited value — the bug); sending the default account through a bare claude turns the two shell tests red.

  • On one machine with two logged-in accounts, in a shell that exports the second account's folder: command claude auth status reported the second account (the old form's behaviour), env -u CLAUDE_CONFIG_DIR claude auth status reported the default account, and the calling shell still had its variable afterwards. Before the change, the old command with a default-account session id printed No conversation found with session ID: … there.

  • Tested by hand on a packaged build of this branch (yarn make, 1.0.98):

    • a default-account session resumed from the Sessions tab into Ghostty: the command typed was env -u CLAUDE_CONFIG_DIR claude --resume <id>, and the resumed session's status showed the default account;
    • the issue's own scenario: inside a Claude Code session of the other account, the default-account command from codev session show was run with -p appended (a non-interactive resume): it found the session and answered;
    • the command from "Copy resume command" for a default-account session, pasted into a shell that exports the other account's CLAUDE_CONFIG_DIR: it resumed the session.

Not verified:

  • A real resume through iTerm2, Terminal.app and cmux (Ghostty was run), and a resume of another account's session from the Sessions tab on this build (that command's form is unchanged).
  • fish (not installed here). The new form has no VAR=value prefix, which fish handles more easily than the old one.
  • cmux puts its own claude shim first on PATH; env … claude reaches it the same way command claude did, and the variable stays unset through it. That is reasoned from the code and from the new-session launcher's existing use of the same form, not run.

Version 1.0.98, with a CHANGELOG entry and the design doc's command description updated.

🤖 Generated with Claude Code