CLI errors after /clear when previous cwd was a removed directory

Resolved 💬 3 comments Opened Mar 21, 2026 by thomasandresen Closed Mar 25, 2026

Description

After /clear, Claude Code tries to restore the working directory from the previous session context. If that directory has been removed (e.g., a git worktree that was cleaned up), the CLI throws a hard error instead of falling back gracefully.

Steps to reproduce

  1. Start Claude Code in a project that uses git worktrees
  2. Enter a worktree (e.g., .claude/worktrees/adhoc-foo)
  3. Remove the worktree (via git worktree remove or PRAM cleanup)
  4. Run /clear

Actual behavior

Error: Path "/path/to/project/.claude/worktrees/adhoc-foo" does not exist

The session breaks and the user must start a fresh claude session.

Expected behavior

The CLI should detect that the saved cwd no longer exists and fall back to the project root (or the nearest existing parent directory), with an informational message like:

Previous working directory no longer exists, falling back to /path/to/project

Context

This is common in workflows that use git worktrees for isolated work sessions. Worktrees are created, used, and then removed after merging — but /clear still references the old path.

Workaround

Start a new claude session instead of using /clear when the worktree has been removed.

View original on GitHub ↗

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