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

[BUG] Working directory does not persist between Bash commands on Windows (Git Bash/Powershell)

Open jaodsilv opened this issue 1 month ago • 5 comments

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

When using Claude Code on Windows with either Git Bash or PowerShell, the working directory does not persist between separate Bash tool invocations, even when CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR=0 is set.

Also tested with the opposite CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR=1 with no change in behavior.

Tested both using ! {command} and asking Claude to run the command with Bash tool with no success either

What Should Happen?

According to the documentation, when CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR=0 (or unset), the working directory should persist between Bash commands.

Error Messages/Logs

No error messages

Steps to Reproduce

  1. set enviroment variable to 0 or unset it:
    1. $env:CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR = 0 in PowerShell
    2. export CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR=0 in Git Bash2. echo the variable to the value is set
  2. Open Claude Code
  3. Run using Bash mode:
    1. Run ! echo $CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR, to see the variable is loaded correctly
    2. Run ! cd some-directory && pwd → outputs "some-directory" path, in my case D:/src/some-directory ✓
    3. Run ! pwd → outputsthe original working directory, in my case /d/src ✗ (should be /d/src/some-directory)
  4. Alternatively run asking Claude to use the Bash tool
    1. Ask CC "Print the environment variable CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR using you Bash tool" to see the variable value is in effect
    2. Ask CC "Run cd some-directory && pwd using you Bash tool" → outputs "some-directory" path, in my case D:/src/some-directory ✓
    3. Ask CC "Run pwd using you Bash tool" → outputsthe original working directory, in my case /d/src ✗ (should be /d/src/some-directory)

Claude Model

Multiple models

Is this a regression?

I don't know, it always behaved like this for me.

Last Working Version

No response

Claude Code Version

2.0.76 (Claude Code)

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

PowerShell, Git Bash

Additional Information

I don't know if there was a regression, but it always behaved like this for me.

jaodsilv avatar Jan 05 '26 15:01 jaodsilv

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/2001
  2. https://github.com/anthropics/claude-code/issues/11067
  3. https://github.com/anthropics/claude-code/issues/4100

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

github-actions[bot] avatar Jan 05 '26 15:01 github-actions[bot]

It is kind of the opposite of issue #2001

jaodsilv avatar Jan 05 '26 15:01 jaodsilv

I'm also running into this issue on Mac OS.

mikolalysenko avatar Jan 08 '26 17:01 mikolalysenko

Confirming this issue on macOS (Darwin 24.6.0)

Claude Code version: 2.1.1 Platform: macOS (darwin)

Testing Results

I tested both values of CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR in .claude/settings.json:

{
  "env": {
    "CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR": "1"
  }
}
Setting Reset Message Actual Directory Behavior
="1" Hidden Directory still resets to project root
="0" Shown ("Shell cwd was reset to...") Directory still resets to project root

Key Finding

The env var only controls whether the "Shell cwd was reset to /path/to/project" message is displayed - it does NOT actually prevent the working directory from resetting.

Reproduction

# With CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR=1
cd /tmp && pwd
# Output: /tmp (no message)

pwd  
# Output: /Users/.../Projects/depscan (reset to project root!)

Workaround

For now, prefix all bash commands with cd <target-dir> &&:

cd /tmp/my-worktree && git status
cd /tmp/my-worktree && pnpm install

This is particularly painful for git worktree workflows where you want to work in a different directory than the project root.

mikolalysenko avatar Jan 08 '26 17:01 mikolalysenko

Confirming this issue on macOS (Darwin 24.6.0)

Claude Code version: 2.1.1 Platform: macOS (darwin)

Testing Results

I tested both values of CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR in .claude/settings.json:

{ "env": { "CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR": "1" } } Setting Reset Message Actual Directory Behavior ="1" Hidden Directory still resets to project root ="0" Shown ("Shell cwd was reset to...") Directory still resets to project root

Key Finding

The env var only controls whether the "Shell cwd was reset to /path/to/project" message is displayed - it does NOT actually prevent the working directory from resetting.

Reproduction

With CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR=1

cd /tmp && pwd

Output: /tmp (no message)

pwd

Output: /Users/.../Projects/depscan (reset to project root!)

Workaround

For now, prefix all bash commands with cd <target-dir> &&:

cd /tmp/my-worktree && git status cd /tmp/my-worktree && pnpm install This is particularly painful for git worktree workflows where you want to work in a different directory than the project root.

Exactly this with the git worktree workflows. Behavior is exactly the same for me.

Benjamin-van-Heerden avatar Jan 09 '26 10:01 Benjamin-van-Heerden