claude-code - 💡(How to fix) Fix Agent crashes with 'exit 1 before init' when cwd no longer exists (e.g. after project move)

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

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.

Error Message

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.

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.

Fix Action

Workaround

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

Code Example

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)
RAW_BUFFERClick to expand / collapse

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.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING