[BUG] Session working directory diverges from the directory Claude Code was launched from
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] 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):
- Launch Claude Code from Dir A.
- Issue a task that pertains to Dir A.
- Observe that the agent's environment reports its primary working directory as Dir B.
- 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_
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗