Agent crashes with 'exit 1 before init' when cwd no longer exists (e.g. after project move)

Status Fixed / completed
Reported on v2.1.150
Maintainer reply ✓ Yes — bogini
Activity 4 comments · opened May 26, 2026 · closed May 27, 2026
💡 Likely answer: A maintainer (bogini, collaborator) responded on this thread — see the highlighted reply below.

Summary

When an agent's working directory is moved or deleted after the agent was created, any attempt to recover or resume that agent results in an immediate crash with exit 1 before init. The error appears in the agents list as a single-line truncated stack trace and the agent cannot be interacted with.

This affects both the daemon backend (~/.claude/jobs/<id>/state.json) and likely the desktop app session layer (~/Library/Application Support/Claude/…) — see #53225 for the desktop-app variant of the same root cause.

Steps to Reproduce

  1. Start an agent in directory ~/Projects/scratch/some-session/
  2. The agent (or a skill it runs) moves the project to a new path, e.g. ~/Projects/my-report/
  3. The original scratch directory is deleted as part of the move
  4. Attempt to recover the agent from the agents list

Observed Behaviour

The agent crashes immediately on spawn with:

exit 1 before init — … (/$bunfs/root/src/entrypoints/cli.js:11884:233)
  at async ovO (/$bunfs/root/src/entrypoints/cli.js:24088:68)
  at async ryO (/$bunfs/root/src/entrypoints/cli.js:24127:313)
Bun v1.3.14 (macOS arm64)

The daemon log shows the agent settling to (crashed) within milliseconds of spawning — it never initialises. The state.json for the job retains the stale cwd / originCwd pointing to the deleted directory, and every recovery attempt re-crashes for the same reason.

Root Cause

Bun exits with code 1 before the CLI runtime initialises if the process working directory does not exist. The cwd and originCwd fields in ~/.claude/jobs/<id>/state.json are set at agent-creation time and are never updated when the project directory changes. There is no fallback to a valid directory (e.g. $HOME) when the stored cwd is missing.

Expected Behaviour

One or more of the following mitigations:

  1. At spawn time: if the stored cwd does not exist, fall back to $HOME (or the nearest existing ancestor) and emit a warning rather than crashing.
  2. At move/rename time: when a skill or agent action relocates the project root, update cwd / originCwd in the corresponding state.json.
  3. In the agents UI: detect a missing cwd and surface a clear "working directory was moved or deleted" message with an option to reassign the path, instead of showing a raw stack trace.

Environment

  • Claude Code 2.1.150
  • macOS arm64 (Darwin 25.5.0)
  • Bun v1.3.14
  • Backend: daemon

Workaround

Manually edit ~/.claude/jobs/<daemonShort>/state.json and update cwd and originCwd to a valid existing directory, then retry recovery.

View original on GitHub ↗

4 Comments

github-actions[bot] · 4 months ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/61740
  2. https://github.com/anthropics/claude-code/issues/57920
  3. https://github.com/anthropics/claude-code/issues/53225

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

sheldon · 4 months ago

Related issues (same problem cluster, different layers)

This issue is not a duplicate of the bot-suggested issues, but they share the same root cause: the daemon/app does not validate that stored cwd/originCwd paths still exist before using them. A coordinated fix across layers would address them together:

| Issue | Layer | Symptom |
|-------|-------|---------|
| #61740 | Daemon spare pool | Pre-warmed spare processes retain deleted worktree cwds, causing orphan session dirs and /clear errors |
| #53225 | Desktop app | No recovery UI when a session's cwd is moved/deleted (~/Library/Application Support/Claude/…) |
| #59361 | Daemon backend | Agent's cwd/originCwd in state.json overridden to ~/.claude at runtime |
| #52747 | Bash tool (closed) | Bash tool permanently broken when CWD is deleted mid-session |
| #57920 | --resume CLI | claude --resume <id> fails after worktree path is removed |

The fix in this issue (spawn-time fallback + update-on-move) would ideally cover both the daemon job layer (~/.claude/jobs/<id>/state.json) and the desktop app session layer (~/Library/Application Support/Claude/…) to close the whole cluster.

bogini collaborator · 4 months ago

Addressed by a merged fix. Please reopen with a fresh repro if you still see this on a current version.

github-actions[bot] · 2 months ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.