Skip to content

fix(accounts): an account-switch restart resumes Claude in the folder it was started in - #33659

Merged
nwparker merged 1 commit into
mainfrom
nwparker/agint-claude-restart-cwd
Oct 25, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/agint-claude-restart-cwd

Conversation

@nwparker

@nwparker nwparker commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​21 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​21
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​5 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​4

ELI5

If you start Claude from a sub-folder (cd pkg && claude) and then switch Claude accounts, Orca restarts the session with claude --resume <id>. That ran in the tab's start folder, so Claude carried on in the wrong folder: it asked to trust the folder and ran without that folder's CLAUDE.md and hooks. Now the restart runs cd pkg && claude --resume <id>, the same way cold restore and sleep wake already do since #33527.

Root cause

  • fix(agents): resume an agent from the folder it ran in, not the pane's start folder #33527 records the folder each Claude/Codex session started in (providerSession.cwd). buildAgentResumeStartupPlan adds cd <cwd> && only when the caller passes launchCwd, the folder the resume shell starts in (src/shared/tui-agent-resume-startup.ts).
  • Cold restore, sleep wake and host-owned resume pass it. The account-switch restart (resolveAgentAccountRestartResumeStartup) did not, so the recorded folder was ignored.
  • Upstream, checked with Claude Code 2.1.310 and a fake Anthropic server (isolated HOME/CLAUDE_CONFIG_DIR): claude --resume <id> resumes from the current folder whatever folder the session started in. SessionStart reports source: resume, cwd: <current folder>, and a new project bucket is created for it.

What changed

  • agent-account-restart-startup.ts: pass launchCwd = the tab's startupCwd, else the worktree path. That is the folder both restart executors spawn in (TerminalOverlaySlot cwd={startupCwd ?? worktreePath} for mounted panes, codex-detached-pane-restart.ts for unmounted ones). A session started in that folder still gets the same bare command as before.
  • One regression test.

How verified

  • Test fails on main (claude '--resume' '<id>') and passes here (cd '/repo/pkg' && claude '--resume' '<id>'). The account-restart, detached/mounted restart executor and session-move suites pass (51 tests). pnpm tc and check:code-quality:changed pass.
  • Real CLI (Claude Code 2.1.310, fake Anthropic server, no model spend): started a session in proj/pkg, then resumed from proj:
    • claude -p again --resume <id> (main's command): SessionStart resume with cwd=/…/proj, plus a new -…-proj project bucket.
    • cd '/…/proj/pkg' && claude -p again --resume <id> (this PR's command): SessionStart resume with cwd=/…/proj/pkg.
  • Also checked that Claude Code emits no OSC 7 while its Bash tool cds (raw PTY capture, 0 sequences). The terminal's tracked folder follows the shell, not the agent.
  • Not run end to end through the account-switch dialog: that needs two real managed Claude logins.

Risk / scope

Refs #31545. Supersedes the folder-matching part of #32033 by @asunghong. That PR derives the folder from the transcript bucket name; #33527 now records it directly from hooks.

Co-authored-by: asunghong [email protected]

… it was started in

The restart built 'claude --resume <id>' without the spawn folder, so #33527's
recorded-cwd prefix never applied and a 'cd pkg && claude' session came back in
the tab's start folder.

Refs #31545

Co-authored-by: asunghong <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

The restart resolver now passes a launch working directory to the resume startup plan. It uses the matching tab’s startupCwd when available and otherwise uses the worktree path. A new test checks that a Claude session recorded in /repo/pkg resumes from that directory, even when the tab starts in /repo.

Priority: Normal

Merge Risk: Moderate · up to 27473

Some Codex sessions may fail to resume after an account switch when their recorded directory is unavailable.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: account-switch restarts now resume Claude in the original working folder.
Description check Passed The description clearly explains the user impact, root cause, implementation, testing, risks, and scope. It does not include the required linked issue format, explicit visual-proof statement, or check…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description clearly explains the user impact, root cause, implementation, testing, risks, and scope. It does not include the required linked issue format, explicit visual-proof statement, or checklist confirmations.

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 05ec0049-adf9-4a7c-a52d-48d2be6b093c
Commits

Reviewing files that changed from the base of the PR and between 47ed6e1 and 27473d8.

Files selected for processing: 2
  • src/renderer/src/lib/agent-account-restart-startup.test.ts
  • src/renderer/src/lib/agent-account-restart-startup.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

Comment on lines +112 to +116
shell: resumeTarget.shell,
// Both restart executors spawn in the tab's start folder.
launchCwd:
state.tabsByWorktree[args.worktreeId]?.find((tab) => tab.id === args.tabId)?.startupCwd ??
worktree?.path

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Major · Stability & Availability · Quick win

Restrict launchCwd to providers that require the original folder.

The account-restart resolver now supplies launchCwd for Codex sessions. The shared builder therefore prefixes the resume command with cd <recorded cwd>. If that recorded directory no longer exists, cd fails and Codex never receives the resume command. Codex can resume from any folder, so preserve its previous command behavior and apply launchCwd only to providers that require it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant