claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

Claude Code loses track of working directory after creating subdirectory

Open ringger opened this issue 3 months ago • 2 comments

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

  1. Ask Claude Code to clone a repository into a subdirectory (e.g., mkdir -p external_data && cd external_data && git clone <repo>)
  2. The command executes successfully and creates the directory structure
  3. Claude Code then tries to explore the newly created directory
  4. Commands like ls external_data/LSLB/ fail with "No such file or directory"
  5. Even though pwd shows 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_data directory
  • Use relative paths correctly (e.g., ls LSLB/ not ls 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 in external_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:

  1. Track the working directory state after cd commands in bash chains
  2. When a bash command includes cd, update internal context about the current working directory
  3. 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.

ringger avatar Dec 16 '25 05:12 ringger