Skip to content

examples: add shell wrapper to fix --resume cwd mismatch#43206

Open
samgdf wants to merge 1 commit intoanthropics:mainfrom
samgdf:fix/resume-cwd-session-43202
Open

examples: add shell wrapper to fix --resume cwd mismatch#43206
samgdf wants to merge 1 commit intoanthropics:mainfrom
samgdf:fix/resume-cwd-session-43202

Conversation

@samgdf
Copy link
Copy Markdown

@samgdf samgdf commented Apr 3, 2026

Summary

  • Adds examples/resume-cwd-wrapper.sh — a shell function that wraps claude to fix session resume failures caused by working directory mismatches
  • Fixes the misleading authentication error thrown when resuming a session from a different directory than where it was started

Root Cause

Sessions are stored at ~/.claude/projects/<ENCODED_CWD>/<session-id>.jsonl where ENCODED_CWD encodes the working directory at session start. When claude --resume <id> is called from a different CWD (e.g. after a directory rename, or in a new shell tab), Claude looks in the wrong project folder, falls through to web-session logic, and throws:

Error: Claude Code web sessions require authentication with a Claude.ai account.

...instead of a meaningful "session not found" message.

Fix

The wrapper shell function:

  1. Intercepts claude --resume <session-id> calls
  2. Searches ~/.claude/projects/ across all project dirs for the matching .jsonl file
  3. Reads the cwd from the first JSONL entry that contains it
  4. cds to that directory before calling the real claude binary, so the project-path lookup succeeds

Usage

Source in ~/.zshrc or ~/.bashrc:

source /path/to/examples/resume-cwd-wrapper.sh

Fixes: #43202

🤖 Generated with Claude Code

…43202)

When `claude --resume <id>` is called from a directory different from
where the session was started, Claude looks in the wrong project folder,
falls through to web-session logic, and throws a misleading auth error.

The wrapper resolves the session file by searching all project dirs,
reads the original cwd from the JSONL, and cd's there before resuming.

Fixes: anthropics#43202
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Resume fails after directory rename in session

1 participant