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

Resolved 💬 3 comments Opened May 26, 2026 by sheldon Closed May 27, 2026

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 ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗