Custom statusLine command resets shell CWD between Bash tool calls
Problem
When a custom statusLine command is configured in ~/.claude/settings.json, the shell's current working directory (CWD) no longer persists between Bash tool calls. Every cd command's effect is lost — the CWD resets to the project's primary working directory after each Bash invocation.
This makes it impossible to cd into a git worktree (or any subdirectory) and have subsequent Bash calls execute there.
Reproduction
- Add a
statusLineto~/.claude/settings.json:
``json``
"statusLine": {
"type": "command",
"command": "bash ~/.claude/statusline-command.sh"
}
- The script itself can be trivial (reads JSON from stdin, prints a formatted line).
- In a Claude Code session, run:
cd /some/other/directory→ succeedspwd→ reports/some/other/directoryduring that call, but the next Bash call reverts to the project root
Without the statusLine config, cd persists correctly across Bash calls as documented.
Investigation
- The status line script (
statusline-command.sh) does NOT itself runcd— it only reads stdin JSON and prints output viaprintf. - The issue appears to be that Claude Code executes the status line command in the same shell context between Bash tool calls, and this execution resets the shell's CWD to the project root.
- This may be an artifact of how the shell subprocess is managed — possibly re-spawning or resetting the shell environment when invoking the status line command.
Expected Behavior
The status line command should not interfere with shell state (CWD, environment variables, etc.) between Bash tool calls. The status line command should either:
- Run in an isolated subprocess/subshell that doesn't affect the main shell's state
- Preserve and restore the CWD after executing the status line command
- Run in a completely separate shell instance
Workaround
Remove the statusLine config from settings. Alternatively, use git -C <path> for git commands and absolute paths for file operations, but this defeats the purpose of cd persistence.
Environment
- Platform: Windows 10 (git-bash shell)
- Claude Code: latest
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗