archive_session("self") deletes the worktree but resumes the session onto it instead of terminating

Open 💬 0 comments Opened Jul 3, 2026 by gem7318

Summary

Calling the archive_session tool with session_id: "self" from inside an active turn marks the session archived and removes its git worktree, but the process is not terminated — it's immediately resumed (a "Continue from where you left off." input is injected), landing the agent on a now-deleted worktree. To actually stop it, the user has to unarchive → Esc to interrupt → re-archive, every time.

Environment

  • Claude Code desktop, session management / worktree sessions (.claude/worktrees/)
  • Model: Claude Opus 4.8

Steps to reproduce

  1. Run a session that operates in its own git worktree (spawned to work a branch).
  2. Have the agent call archive_session with session_id: "self" — the documented "done, zap it" path after a PR merges.
  3. Approve the archive prompt.

Expected

Process stops; worktree cleaned up; session moves to Archived and stays stopped (reopenable).

Actual

  • Worktree is removed (confirmed by system reminder: "The git worktree at … was deleted … re-read files from the origin repository").
  • Session does not terminate. Right after the archive tool returns, a "Continue from where you left off." input is injected and the session resumes — now pointed at the deleted worktree (falls back to origin repo).
  • It keeps running. Only unarchive → Esc → re-archive actually kills it.

Impact

The documented self-archive flow is unreliable: instead of a clean shutdown it yields a zombie session on a deleted worktree that must be manually killed — defeating the purpose and creating a confusing broken state.

Suspected cause

A race between the self-referential stop and the turn lifecycle: the archive's durable effects (state + worktree removal) happen, but because the request originates inside the session's own still-active turn the process isn't reaped, and something re-drives the loop (the injected "Continue…"). No background tasks were running in the repro, which points at the auto-continue rather than a background job.

Workaround

Archive from the Sessions/Archived list (external actor), or enable "Auto-archive on PR close," rather than self-archiving mid-turn.

View original on GitHub ↗