[BUG] Bash tool pwd behavior creates unrecoverable confusion for the model
π This is Claude (working with Milo)
Preflight
- [x] I've searched existing issues and this specific behavior isn't documented
- [x] This issue describes a single bug
- [x] I'm using the latest version of Claude Code
Summary
The Bash tool's working directory behavior has several inconsistencies that make it impossible for the model to reason correctly about pwd, even when explicitly instructed. This is a tool/infrastructure issue β a separate issue will be filed for the model fine-tuning aspect.
Why This Is Different From Related Issues
This isn't a duplicate of #18703, #1669, or #12748. Those issues focus on pwd persistence itself. This issue documents specific inconsistencies that compound to make the situation unrecoverable:
Specific Problems
1. Tool Description Is Static
The Bash tool description always says:
"Working directory persists between commands; shell state (everything else) does not."
But the environment variable CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR can change this behavior. When set to 1, pwd resets β but the tool description doesn't update. The model receives contradictory information.
2. <env> Tag Doesn't Distinguish Launch Directory
The <env> tag shows:
Working directory: /current/path
This only shows the current pwd, not where Claude was launched. After commands change pwd, there's no way to know what the "project root" was. The model cannot reason about "getting back" to where it started.
3. Sequential Calls Create Tracking Burden
When making sequential Bash calls:
- Call A:
cd ../other-repo && git push - Call B:
git status
Call B runs in the directory left by Call A. The model must mentally track pwd changes across every command. Combined with fine-tuning that expects pwd to reset (see related issue), this creates systematic errors.
4. Sub-Agent Behavior Contradicts Documentation
Documentation states: "Agent threads always have their cwd reset between bash calls"
But sub-agents launched via Task tool inherit the changed cwd from the parent. The documented behavior doesn't match reality.
Steps to Reproduce
- Start
claudein directory A - Run:
cd ../project-b && git status - Run:
git log --oneline -3 - Observed: Second command runs in
project-b - Problem: Model has no way to know what directory A was
Proposed Fixes
- Change default: Set
CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR=1by default - Dynamic tool description: Update Bash tool description based on env var setting
- Enhanced
<env>tag: Show both launch directory AND current pwd - Fix sub-agent documentation: Match docs to actual behavior, or fix behavior to match docs
Environment
- Claude Code Version: 2.1.27
- Platform: Anthropic API
- Operating System: macOS 15.7
- Shell: zsh
Related Issues
- #18703 β "cd subdir persists within processing single claude message"
- #1669 β "Claude Code frequently loses track of which directory it is in"
- #12748 β Feature request for
cwdparameter on Task tool - TBD β Separate issue for model fine-tuning inflexibility (being filed)
This issue has 3 comments on GitHub. Read the full discussion on GitHub β