claude-code
claude-code copied to clipboard
Claude Code loses track of working directory after creating subdirectory
Claude Code loses track of working directory after creating subdirectory
Description
Claude Code sometimes loses track of its working directory after creating a new subdirectory and attempting to work within it. This leads to confusing behavior where the assistant can't find files it just created.
Steps to Reproduce
- Ask Claude Code to clone a repository into a subdirectory (e.g.,
mkdir -p external_data && cd external_data && git clone <repo>) - The command executes successfully and creates the directory structure
- Claude Code then tries to explore the newly created directory
- Commands like
ls external_data/LSLB/fail with "No such file or directory" - Even though
pwdshows the current directory is/path/to/project/external_data
Expected Behavior
After running mkdir -p external_data && cd external_data && git clone ..., Claude Code should:
- Understand it's now in the
external_datadirectory - Use relative paths correctly (e.g.,
ls LSLB/notls external_data/LSLB/) - Or navigate back to project root if needed
Actual Behavior
Claude Code appears to lose context about where it is:
- Uses incorrect paths like
external_data/LSLB/when already inexternal_data/ - Doesn't recognize that the directory was successfully created
- Continues to fail until user manually points out the working directory issue
Example Session
# Command 1 - succeeds
$ mkdir -p external_data && cd external_data && git clone https://github.com/ctaguchi/LSLB.git
Cloning into 'LSLB'...
# Command 2 - pwd shows we're in external_data
$ pwd
/Users/ringger/Projects/mtsurvey/external_data
# Command 3 - but then uses wrong path
$ ls external_data/LSLB/
ls: external_data/LSLB/: No such file or directory
# Should have been:
$ ls LSLB/
# or
$ ls /Users/ringger/Projects/mtsurvey/external_data/LSLB/
Suggested Fix
Claude Code should:
- Track the working directory state after
cdcommands in bash chains - When a bash command includes
cd, update internal context about the current working directory - Or preferably, follow the CLAUDE.md guidance to "maintain your current working directory throughout the session by using absolute paths and avoiding usage of
cd"
Impact
- Wastes time with failed commands
- Creates confusion about whether operations succeeded
- User must manually intervene to remind Claude Code where it is
Environment
- OS: macOS (Darwin 24.6.0)
- Claude Code: Latest version
- Shell: bash
Additional Context
The CLAUDE.md documentation already suggests avoiding cd and using absolute paths, but when cd is used (especially in compound commands), Claude Code should track the state change properly.