| name | repair-session-path |
| description | Use when a Claude Code session is orphaned, its working directory was deleted, or you need to relocate a session to a different project directory. Triggers on "session not found", "folder no longer exists", orphaned session recovery. |
Session Path Correction
Claude Code stores sessions under ~/.claude/projects/<encoded-cwd>/. The project directory is determined by the working directory when the session starts. If the session's cwd directory is deleted during the session, the session becomes orphaned — it won't appear in claude -c from any existing directory.
Prevention
- NEVER delete, deinit, or remove the directory a session is running from. If you need to restructure a repo (moving submodules, deiniting directories, etc.), do it from the repo root — not from inside a subdirectory that will be removed.
- If you must remove the current working directory (e.g., replacing a submodule with a new structure), switch the session's working directory to the repo root FIRST by running commands with absolute paths from the parent.
Recovery: Relocate a session
-
Encode the target path by replacing every / with - (e.g., /Users/asher/Dropbox/Projects/xnn → -Users-asher-Dropbox-Projects-xnn).
-
Find the session files under ~/.claude/projects/<old-encoded-path>/:
<session-id>.jsonl — the transcript
<session-id>/ — subdirectory containing subagents/ and tool-results/
-
Ensure the target project directory exists:
mkdir -p ~/.claude/projects/<new-encoded-path>
-
Move both the jsonl file and the subdirectory:
mv ~/.claude/projects/<old>/<session-id>.jsonl ~/.claude/projects/<new>/
mv ~/.claude/projects/<old>/<session-id>/ ~/.claude/projects/<new>/
-
Verify by running claude --resume <session-id> from the target directory, or claude -c if it should be the most recent session there.
-
Update cwd fields inside the jsonl to match the new path:
sed -i '' 's|"cwd":"/old/path"|"cwd":"/new/path"|g' ~/.claude/projects/<new>/<session-id>.jsonl
-
Desktop app sessions (CRITICAL): The Claude desktop app stores its own session metadata at ~/Library/Application Support/Claude/claude-code-sessions/<accountId>/<orgId>/local_<sessionId>.json. Each file contains cwd, originCwd, and optionally worktreePath/worktreeName fields. These must also be updated:
grep -rl "/old/path" ~/Library/Application\ Support/Claude/claude-code-sessions/ 2>/dev/null
sed -i '' 's|/old/path|/new/path|g' <each matching file>
Also check ~/Library/Application Support/Claude/git-worktrees.json if the session used a worktree. Restart the desktop app after editing.