Preflight Checklist
What's Wrong?
The Bash Tool consistently executes commands from the user's home directory instead of the working directory specified in the environment, despite the environment indicating a different working directory and Shell cwd was reset messages appearing after command execution
What Should Happen?
When the environment specifies a working directory of /Users/username/Projects/myproject, bash commands should execute from that directory
Error Messages/Logs
All bash commands execute from `/Users/username` (home directory), regardless of the working directory specified in the environment. After each command completes, a message appears: `Shell cwd was reset to /Users/username/Projects/myproject`, but subsequent commands still execute from the home directory
Steps to Reproduce
Test Cases to Reproduce
Test 1: Basic pwd check
Command: pwd
Expected output: /Users/username/Projects/myproject
Actual output: /Users/username
Post-execution message: Shell cwd was reset to /Users/username/Projects/myproject
Test 2: File existence check
Command: ls project-file.json
Expected: File listed (exists in /Users/username/Projects/myproject/)
Actual: ls: project-file.json : No such file or directory
Reason: Command runs from /Users/username instead of project directory
Test 3: Environment variable check
Command: echo "PWD: $PWD" && echo "HOME: $HOME" && echo "OLDPWD: $OLDPWD"
Output:
PWD: /Users/username
HOME: /Users/username
OLDPWD: /Users/username/Projects/myproject
Post-execution message: Shell cwd was reset to /Users/username/Projects/myproject
Analysis: PWD shows home directory, OLDPWD shows the intended working directory
Test 4: Sequential commands
Command 1: pwd
Result: /Users/username
Message: Shell cwd was reset to /Users/username/Projects/myproject
Command 2: pwd (immediately after)
Result: /Users/username (still wrong)
Message: Shell cwd was reset to /Users/username/Projects/myproject
Test 5: Absolute path verification
Command: ls /Users/username/Projects/myproject/project-file.json
Result: SUCCESS - file exists at absolute path
Command: ls project-file.json
Result: FAIL - No such file or directory
Conclusion: Files exist in the project directory, but commands don't execute from there
Claude Model
Sonnet (default)
Is this a regression?
I don't know
Last Working Version
No response
Claude Code Version
Claude Code v2.0.33
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
VS Code integrated terminal
Additional Information
This issue prevents commands that require execution from a specific directory from working
Examples:
- Build tools that look for configuration files in the current directory
- Package managers (
npm, pip, etc.) that need to run from project root
- Git commands when repository isn't at home directory
- CLI tools that use
./config or relative paths
Workarounds Attempted
-
Using cd command
Command: cd /Users/username/Projects/myproject && ls project-file.json
Result: cd command appears to be filtered/stripped out, file not found
-
Using subshell
Command: (cd /Users/username/Projects/myproject && pwd)
Result: Still shows /Users/username
-
Using absolute paths with git -C
Command: git -C /Users/username/Projects/myproject status
Result: SUCCESS - This workaround works for git commands
Analysis
The issue appears to be that:
- Each Bash Tool invocation starts a fresh shell in the home directory
- The
Shell cwd was reset message suggests an attempt to change directory, but this happens AFTER command execution
- The Bash Tool guidelines recommend avoiding
cd commands, but the tool also doesn't maintain working directory between invocations
- This creates a catch-22 where directory-dependent commands cannot be executed
Suggested Fix
Either:
- Ensure each
bash command starts in the working directory specified in the environment before executing the command
- Allow
cd commands when necessary for tools that require specific working directories
- Provide a parameter to the Bash Tool to specify the working directory for that specific command
- Maintain a persistent shell session that respects directory changes
Additional Context
The Bash Tool documentation states: "Try to maintain your current working directory throughout the session by using absolute paths and avoiding usage of cd." However, when tools require execution from a specific directory and don't support absolute path parameters, this guidance cannot be followed
Preflight Checklist
What's Wrong?
The Bash Tool consistently executes commands from the user's home directory instead of the working directory specified in the environment, despite the environment indicating a different working directory and
Shell cwd was resetmessages appearing after command executionWhat Should Happen?
When the environment specifies a working directory of
/Users/username/Projects/myproject, bash commands should execute from that directoryError Messages/Logs
Steps to Reproduce
Test Cases to Reproduce
Test 1: Basic pwd check
Command:
pwdExpected output:
/Users/username/Projects/myprojectActual output:
/Users/usernamePost-execution message:
Shell cwd was reset to /Users/username/Projects/myprojectTest 2: File existence check
Command:
ls project-file.jsonExpected: File listed (exists in
/Users/username/Projects/myproject/)Actual:
ls: project-file.json : No such file or directoryReason: Command runs from
/Users/usernameinstead of project directoryTest 3: Environment variable check
Command:
echo "PWD: $PWD" && echo "HOME: $HOME" && echo "OLDPWD: $OLDPWD"Output:
PWD: /Users/usernameHOME: /Users/usernameOLDPWD: /Users/username/Projects/myprojectPost-execution message:
Shell cwd was reset to /Users/username/Projects/myprojectAnalysis:
PWDshows home directory,OLDPWDshows the intended working directoryTest 4: Sequential commands
Command 1:
pwdResult:
/Users/usernameMessage:
Shell cwd was reset to /Users/username/Projects/myprojectCommand 2:
pwd(immediately after)Result:
/Users/username(still wrong)Message:
Shell cwd was reset to /Users/username/Projects/myprojectTest 5: Absolute path verification
Command:
ls /Users/username/Projects/myproject/project-file.jsonResult: SUCCESS - file exists at absolute path
Command:
ls project-file.jsonResult: FAIL -
No such file or directoryConclusion: Files exist in the project directory, but commands don't execute from there
Claude Model
Sonnet (default)
Is this a regression?
I don't know
Last Working Version
No response
Claude Code Version
Claude Code v2.0.33
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
VS Code integrated terminal
Additional Information
This issue prevents commands that require execution from a specific directory from working
Examples:
npm,pip, etc.) that need to run from project root./configor relative pathsWorkarounds Attempted
Using
cdcommandCommand:
cd /Users/username/Projects/myproject && ls project-file.jsonResult:
cdcommand appears to be filtered/stripped out, file not foundUsing subshell
Command:
(cd /Users/username/Projects/myproject && pwd)Result: Still shows
/Users/usernameUsing absolute paths with
git -CCommand:
git -C /Users/username/Projects/myproject statusResult: SUCCESS - This workaround works for
gitcommandsAnalysis
The issue appears to be that:
Shell cwd was resetmessage suggests an attempt to change directory, but this happens AFTER command executioncdcommands, but the tool also doesn't maintain working directory between invocationsSuggested Fix
Either:
bashcommand starts in the working directory specified in the environment before executing the commandcdcommands when necessary for tools that require specific working directoriesAdditional Context
The Bash Tool documentation states: "Try to maintain your current working directory throughout the session by using absolute paths and avoiding usage of
cd." However, when tools require execution from a specific directory and don't support absolute path parameters, this guidance cannot be followed