Skip to content

fix(panes): Open shell and a fresh Restart agent start in the last known folder (#376) - #411

Merged
bRRRITSCOLD merged 1 commit into
mainfrom
fix/376-respawn-folder
Nov 24, 2026
Merged

bRRRITSCOLD merged 1 commit into
mainfrom
fix/376-respawn-folder

Conversation

@bRRRITSCOLD

Copy link
Copy Markdown
Owner

Closes #376

What changes

POST /v1/panes/{id}/respawn (the exited Pane header's Restart agent and Open shell) no longer always starts in the launch folder (cwd). Before, it also refused with invalid_dir once that folder was gone.

Case Starts in Why
Open shell (run: "shell") last known folder, else cwd, else ~ A shell has no session. It should come back where the user cd'd to before it exited, as a Pane restored after a daemon restart already does (#367).
Fresh Restart agent (claude/codex with no known session, an other agent run again) last known folder, else cwd, else ~ A fresh start has no session to find, so it follows the same rule as Open shell.
Resume (claude --resume <id>, codex resume <id>) cwd, the folder its session started in Claude Code keeps a session under the folder it started in and finds it only from there. Codex finds a session by id from any folder, but when the current folder isn't the one the session recorded, codex-cli 0.171.0 stops and asks "Use session directory" / "Use current directory" before it resumes. Resuming anywhere else therefore either fails or waits on a question.
Resume, cwd gone a fresh start, placed as above The session can't be resumed there, so the daemon starts fresh, as the existing "resume that fails at once" fallback would, and logs it at info. It no longer refuses with invalid_dir.

The folder a respawn starts in now becomes the Pane's cwd as well as its folder. Without that, a fresh start in another folder would create a session that a later Restart agent then tries to resume from the old cwd, where it can't be found. A resume after a daemon restart still leaves cwd as #378 left it. invalid_dir (400) now means that none of the three folders exists.

An agent's own folder never moves, so for an agent Pane folder and cwd stay equal until a folder is removed. The resume/fresh split only changes what happens in that case.

Code

  • agents::restart::place: a pure function that takes a respawn, the launch folder, the last known folder and $HOME, and returns what to run and the folder to run it in. Respawn::Resume is now its own variant, separate from an other agent's Again. existing_dir and home are shared with the restore path in resume.rs.
  • pane_respawn reads the live folder, uses place, and answers invalid_dir only when no folder is left.
  • db::panes::respawned also records cwd.
  • API_VERSION 29: the route's behaviour and the cwd / folder field docs changed. openapi.json and the client are regenerated.
  • docs/spec.md: §2 version note, §3 (cwd), the §4 respawn row with the rule and the reasoning, §6 "Where a pane starts", and §11 Open shell.

Tests

  • Unit: place covers resume in the launch folder, resume falling back to fresh, shell and fresh in the last known folder, the launch-folder and ~ fallbacks, a relative folder skipped, and nothing left.
  • Integration (folders::post_v1_panes_id_respawn, a real daemon with sh and the stub agents, which now record the folder each launch started in):
    • Open shell starts in the last known folder, then the launch folder once that is gone, then ~ once both are gone. An exited agent Pane's Open shell starts in its last known folder.
    • A fresh Restart agent (codex with its session forgotten) starts in the last known folder, then the launch folder, then ~. An other agent runs again in its last known folder.
    • claude and codex resume in the launch folder even when the last known folder differs. With the launch folder gone, claude starts fresh in the last known folder, and a later Restart agent resumes that new session where it started.

Before the fix, 9 of the 12 new integration tests failed. The other 3 cover behaviour that was already right.

File links in a Pane without OSC 7 still resolve against the launch folder in the GUI. That is tracked in #377 and is not changed here.

🤖 Generated with Claude Code

…own folder (#376)

POST /v1/panes/{id}/respawn started every process in the Pane's launch
folder (cwd) and refused with invalid_dir once it was gone. Now a claude
or codex resume runs in cwd, the folder its session started in (Claude
Code finds a session only from there; Codex asks which folder to use when
they differ), and starts fresh once cwd is gone. Open shell, a fresh
start and an `other` agent run again start in the last known folder,
else cwd, else ~. The folder a respawn starts in becomes the Pane's cwd
too, so a later resume finds a session started fresh elsewhere.
API_VERSION 29.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bRRRITSCOLD
bRRRITSCOLD merged commit bc5631e into main Nov 24, 2026
6 checks passed
@bRRRITSCOLD
bRRRITSCOLD deleted the fix/376-respawn-folder branch November 24, 2026 01:49
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.

Restart agent and Open shell start in the launch folder, not the Pane's last known folder

1 participant