[BUG] Claude misunderstands the meaning and nature of "Working directory" in the system context <env> section
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?
Claude is confused about the meaning of "Working directory" in the system context
Even the user-facing Write tool output get's this wrong (see screenshot). So there might even be "internal" confusion about working directories.
This can cause very erratic, even destructive behavior when for example working in a project directory that has subdirectories that are git repos.
Currently Claude doesn't get any information about the project directory, but has to infer it instead.
What Should Happen?
Recommended fix:
Only include a static "Project directory" in the system context
Intermediate fix: Explaining "Working directory"'s meaning mitigates erratic behaviour. They still sometimes do things in the wrong directory, but immediately realize their mistake and recover.
Example for CLAUDE.md:
Error Messages/Logs
Transcript: (Note: there was a rewind from a subdir in this session - Claude Code's starting directory was /home/jan/tmp/test15, but Claude's confusion also stays true for linear sessions)
╭──────────────────────────────────────────────────────────────╮
│ ✻ Welcome to Claude Code! │
│ │
│ /help for help, /status for your current setup │
│ │
│ cwd: /home/jan/tmp/test15/kitten_dir/kitten_subdir/newdir │
│ │
│ ────────────────────────────────────────────────────────── │
│ │
│ Overrides (via env): │
│ │
│ • Max thinking tokens: 14000 │
╰──────────────────────────────────────────────────────────────╯
Tips for getting started:
Run /init to create a CLAUDE.md file with instructions for Claude
Use Claude to help with file analysis, editing, bash commands and git
Be as specific as you would with another engineer for the best results
> what is the exact meaning of "Working directory" in <env>?
✻ Thinking…
The user is asking about the specific meaning of "Working directory" in the section that was provided to me. Let me look at
what was shown:
The user wants to know what "Working directory" means in this context. This is a straightforward question about the meaning of
a term in the environment information.
The working directory refers to the current directory that I'm operating in - it's the directory where any relative file paths
would be resolved from, and where commands would be executed by default. It's equivalent to what you'd get if you ran pwd
(print working directory) in a shell.
This is a simple, direct question that doesn't require tool use - just a concise explanation.
● The "Working directory" is the current directory where Claude Code is operating - equivalent to running pwd in a shell.
All relative file paths and commands execute from this location: /home/jan/tmp/test15.
> tell me without testing: if you use cd with the bash tool, will the <env> "Working directory" change?
✻ Thinking…
The user is asking about whether using cd with the Bash tool will change the "Working directory" shown in the section.
Looking at the Bash tool description, I can see this relevant information:
"Try to maintain your current working directory throughout the session by using absolute paths and avoiding usage of cd. You
may use cd if the User explicitly requests it."
And also:
"
pytest /foo/bar/tests
cd /foo/bar && pytest tests
"
This suggests that the Bash tool operates in a persistent shell session, but the tool description specifically recommends
avoiding cd and using absolute paths instead. However, it doesn't explicitly state whether the "Working directory" would
update.
But based on my understanding of how these systems typically work, the section is likely set at the beginning of the session
and represents the initial working directory where Claude Code was started. The Bash tool probably maintains its own shell
session state, but the "Working directory" is more likely a static piece of information about where the Claude Code session
was initiated, not something that dynamically updates based on shell commands.
The user specifically asked me to answer "without testing", so I should give my best assessment based on the available
information.
● No, the "Working directory" will not change. It represents the initial directory where Claude Code was started, not the
current shell working directory. The Bash tool maintains its own persistent shell session state, but the section shows
static session information.
> please test your thesis by creating a new directory newdir, cd into that and tell me what <env> "Working directory" says
now.
✻ Thinking…
The user wants me to test my thesis about whether the "Working directory" changes when I use cd with the bash tool. Let me
create a new directory, cd into it, and then check what the says.
I need to:
1. Create a new directory called "newdir"
2. cd into that directory
3. Check what the "Working directory" shows
Let me do this step by step.
● Bash(mkdir newdir && cd newdir && pwd)
⎿ /home/jan/tmp/test15/kitten_dir/kitten_subdir/newdir
✻ Thinking…
Now let me check what the "Working directory" shows. Actually, I can just look at it - the section was provided at the
beginning and shows:
Working directory: /home/jan/tmp/test15/kitten_dir/kitten_subdir
So even though I created newdir and cd'd into it (as confirmed by pwd showing
/home/jan/tmp/test15/kitten_dir/kitten_subdir/newdir), the "Working directory" still shows the original location.
This confirms my thesis was correct - the "Working directory" doesn't change when using cd with the bash tool.
● You're right to test it. I created newdir and cd'd into it - pwd confirms I'm now in
/home/jan/tmp/test15/kitten_dir/kitten_subdir/newdir.
However, the "Working directory" still shows: /home/jan/tmp/test15/kitten_dir/kitten_subdir
My thesis was correct - the "Working directory" remains static and shows the initial session directory, not the current
shell working directory.
> What does the "Working directory" say now?
✻ Thinking…
The user is asking what the "Working directory" says now in the section. Let me look at the current information that was
provided at the beginning of our conversation:
Wait, that's interesting! The working directory in the section now shows /home/jan/tmp/test15/kitten_dir/kitten_subdir/newdir
- which means it DID update! This contradicts my earlier thesis.
So it seems like the "Working directory" does actually change when I use cd with the bash tool. My thesis was wrong.
● The "Working directory" now says: /home/jan/tmp/test15/kitten_dir/kitten_subdir/newdir
My thesis was wrong! The "Working directory" does update when using cd with the Bash tool. It's not static as I initially
thought.
Steps to Reproduce
see transcript
Claude Model
Sonnet (default)
Is this a regression?
I don't know
Last Working Version
No response
Claude Code Version
v1.0.120
Platform
Anthropic API
Operating System
Ubuntu/Debian Linux
Terminal/Shell
Other
Additional Information
No response
This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.