Background sessions should recover gracefully when working directory no longer exists
Open 💬 0 comments Opened Jun 21, 2026 by sheldon
Problem
When a background session's working directory is deleted (e.g. a temporary scratch folder is cleaned up), the session enters a hard failed state with no recovery path:
{
"state": "failed",
"detail": "working directory no longer exists: /Users/sheldonels/Projects/scratch/2026-05-28_083323"
}
The only workaround today is to manually recreate the exact directory and retry. Users have no in-product way to know this, and for sessions created in temporary/dated folders this is a near-certain failure mode over time.
Expected behavior
When a session tries to resume and its original cwd no longer exists, it should:
- Detect the missing directory at resume time rather than hard-failing silently
- Prompt the user to choose a recovery directory (e.g. "The original folder
/path/to/oldno longer exists. Where should this session resume from?") - Resume from the user-chosen directory, updating
cwdin the session state
Alternatively, fall back to a configurable default (e.g. $HOME or the project root) with a visible warning.
Why this matters
- Background sessions ("coffee sessions") are often created from dated scratch dirs that get cleaned up naturally
- The session's
intentandtimeline.jsonlare fully preserved — the conversation is intact, only thecwdis stale - Hard-failing the entire session on a missing
cwdthrows away all that preserved context for a fixable condition
Steps to reproduce
- Start a background session from a temporary directory (e.g.
~/scratch/2026-05-28_083323) - Delete that directory
- Attempt to resume the session → it enters
state: failedwith no in-app recovery prompt
Environment
- Claude Code CLI v2.1.156
- macOS (darwin/zsh)