claude-code - 💡(How to fix) Fix [BUG] Session working directory diverges from the directory Claude Code was launched from

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…

Error Message

Error Messages/Logs

Fix Action

Fix / Workaround

Workaround used: Operated on the correct project exclusively via absolute paths (git -C <abs-path> …), ignoring the session cwd entirely.

RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

Summary: Claude Code was launched from one project directory, but the agent's session working directory resolved to a different, unrelated project directory. The agent's shell (pwd) and the session's reported "primary working directory" both pointed at the wrong project, causing the agent to attempt work against the wrong repository.

What Should Happen?

CWD should not default to other directory than launch Directory of current should show in agent list

Error Messages/Logs

Steps to Reproduce

Title: Session working directory diverges from the directory Claude Code was launched from

Summary: Claude Code was launched from one project directory, but the agent's session working directory resolved to a different, unrelated project directory. The agent's shell (pwd) and the session's reported "primary working directory" both pointed at the wrong project, causing the agent to attempt work against the wrong repository.

Environment:

  • OS: macOS (darwin)
  • Shell: bash
  • Claude Code: <run: claude --version>
  • Two sibling project directories existed on disk:
    • Dir A — where the CLI was actually launched (the intended project)
    • Dir B — an unrelated project; the session's cwd resolved here

Steps to reproduce (observed):

  1. Launch Claude Code from Dir A.
  2. Issue a task that pertains to Dir A.
  3. Observe that the agent's environment reports its primary working directory as Dir B.
  4. pwd and git rev-parse --show-toplevel inside the agent's Bash tool both return Dir B.

Expected: The session working directory should equal the directory the CLI was launched from (Dir A). pwd and the reported primary working directory should match the launch directory.

Actual:

  • Session "primary working directory" = Dir B (not the launch dir).
  • Agent shell pwd = Dir B.
  • After a cd inside a single Bash command, the shell cwd was reset back to Dir B on the next command (cwd appears pinned to the wrong primary working directory).
  • Result: the agent began operating against the wrong repository — including attempting to clone a project that already existed locally — before the mismatch was caught.

Impact:

  • Agent works in the wrong project context; file searches, git operations, and edits target the wrong repo.
  • Wasted turns, tokens, and effort; risk of changes landing in the wrong repository if not caught.
  • Erodes trust in the displayed/active working directory.

Notes / possible causes to investigate (unconfirmed):

  • Possible restoration of a prior session's working directory (e.g., resume/continue state) overriding the launch directory.
  • Possible influence from project-level config or a nested config directory resolving to a sibling project.
  • Whether the reported "primary working directory" is derived from launch cwd vs. some cached/last-used value.

Workaround used: Operated on the correct project exclusively via absolute paths (git -C <abs-path> …), ignoring the session cwd entirely.

Claude Model

None

Is this a regression?

Yes, this worked in a previous version

Last Working Version

No response

Claude Code Version

2.1.156 (Claude Code)

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

No response

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

claude-code - 💡(How to fix) Fix [BUG] Session working directory diverges from the directory Claude Code was launched from