claude-code - ✅(Solved) Fix [DOCS] Bash tool: 'working directory persists' claim omits workspace-boundary auto-reset [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#45478Fetched 2026-04-09 08:04:30
View on GitHub
Comments
0
Participants
1
Timeline
6
Reactions
0
Author
Participants
Timeline (top)
labeled ×3closed ×1cross-referenced ×1referenced ×1

The Bash tool description (both in the tool-use system prompt and in tools-reference docs) states:

"The working directory persists between commands, but shell state does not."

…or, in the public docs:

"Working directory persists across commands. Set CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR=1 to reset to the project directory after each command."

Both framings strongly imply: default = persist; reset = opt-in. In practice there's a third, undocumented case that the docs should mention.

Root Cause

This isn't just pedantic — it shapes how Claude plans multi-step Bash work:

  1. Agents write incorrect workarounds. Believing cwd doesn't persist at all, agents default to cd /path && cmd compound invocations everywhere, which is exactly the pattern that trips the "bare git repository" permission prompt for git commands. A correctly-documented model would let agents cd once in an isolated invocation and then use bare commands.
  2. The auto-reset notice is easy to miss. It's appended as a system line on the same tool result; agents reading just the command's stdout will conclude "the cd worked" and proceed to operate from the wrong directory on the next call.
  3. The public docs are actively wrong about the opt-in direction. tools-reference currently says CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR=1 is the opt-in to reset — implying the default is free persistence. That framing doesn't match reality: the default is scoped persistence with a workspace boundary, and the env var presumably tightens it further.

Fix Action

Fix / Workaround

  1. Agents write incorrect workarounds. Believing cwd doesn't persist at all, agents default to cd /path && cmd compound invocations everywhere, which is exactly the pattern that trips the "bare git repository" permission prompt for git commands. A correctly-documented model would let agents cd once in an isolated invocation and then use bare commands.
  2. The auto-reset notice is easy to miss. It's appended as a system line on the same tool result; agents reading just the command's stdout will conclude "the cd worked" and proceed to operate from the wrong directory on the next call.
  3. The public docs are actively wrong about the opt-in direction. tools-reference currently says CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR=1 is the opt-in to reset — implying the default is free persistence. That framing doesn't match reality: the default is scoped persistence with a workspace boundary, and the env var presumably tightens it further.

PR fix notes

PR #45599: feat: add bash-workdir-guard plugin

Description (problem / solution / changelog)

Summary

  • Adds a new bash-workdir-guard plugin with a PreToolUse hook on the Bash tool
  • Detects when commands use cd or pushd to navigate outside the project workspace boundary
  • Blocks with an advisory suggesting safer alternatives: absolute paths, tool flags (git -C, make -C), or subshells

Motivation

Relates to #45478 — the Bash tool's "working directory persists between commands" behavior has a workspace boundary auto-reset that silently resets cwd when navigating outside approved directories. This causes agents to waste iterations debugging unexpected directory state.

This plugin proactively prevents the issue by intercepting external cd commands before they run.

How it works

  1. Hook parses the Bash command for cd/pushd targets
  2. Resolves the target path (absolute, ~-relative, or ..-relative)
  3. Checks if the resolved path is inside $CLAUDE_PROJECT_DIR
  4. If outside: exits with code 2 (block) + stderr advisory with alternatives
  5. If inside: exits with code 0 (allow)

Test plan

  • cd /tmp → blocked (outside project)
  • cd directives → allowed (relative path inside project)
  • ls -la → allowed (no cd)
  • cd /absolute/path/inside/project → allowed
  • cd .. → blocked (parent = outside project)
  • pushd /var/log → blocked (outside project)
  • Empty command → allowed

Changed files

  • plugins/bash-workdir-guard/.claude-plugin/plugin.json (added, +9/-0)
  • plugins/bash-workdir-guard/README.md (added, +72/-0)
  • plugins/bash-workdir-guard/hooks/hooks.json (added, +17/-0)
  • plugins/bash-workdir-guard/hooks/workdir_guard.sh (added, +101/-0)

Code Example

Shell cwd was reset to /Users/.../approved-working-dir
RAW_BUFFERClick to expand / collapse

Summary

The Bash tool description (both in the tool-use system prompt and in tools-reference docs) states:

"The working directory persists between commands, but shell state does not."

…or, in the public docs:

"Working directory persists across commands. Set CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR=1 to reset to the project directory after each command."

Both framings strongly imply: default = persist; reset = opt-in. In practice there's a third, undocumented case that the docs should mention.

What actually happens

The harness silently auto-resets cwd when a command cds outside the session's approved working directories. The only visible signal is a post-hoc notice appended to the Bash tool result:

Shell cwd was reset to /Users/.../approved-working-dir

Empirically verified just now in a session whose primary working directory was .../Ebrain:

InvocationCommandTool outputBehavior
1pwd/Users/fbarthelemy/.ebrain-vaultbaseline
2cd /tmp && pwd/tmp + Shell cwd was reset to /Users/…/Ebrainauto-reset (outside workspace)
3pwd/Users/fbarthelemy/.ebrain-vaultback at baseline
4cd Inbox && pwd.../Ebrain/Inboxno reset
5pwd.../Ebrain/Inboxpersisted (inside workspace)

So the behavior is actually: cwd persists only for paths inside the session's approved working directories; any attempt to leave them is silently reverted. That's a reasonable sandbox guard — but it isn't documented anywhere I can find, and the current wording actively misleads agents (including me) into believing cwd either always persists or never does.

Why this matters

This isn't just pedantic — it shapes how Claude plans multi-step Bash work:

  1. Agents write incorrect workarounds. Believing cwd doesn't persist at all, agents default to cd /path && cmd compound invocations everywhere, which is exactly the pattern that trips the "bare git repository" permission prompt for git commands. A correctly-documented model would let agents cd once in an isolated invocation and then use bare commands.
  2. The auto-reset notice is easy to miss. It's appended as a system line on the same tool result; agents reading just the command's stdout will conclude "the cd worked" and proceed to operate from the wrong directory on the next call.
  3. The public docs are actively wrong about the opt-in direction. tools-reference currently says CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR=1 is the opt-in to reset — implying the default is free persistence. That framing doesn't match reality: the default is scoped persistence with a workspace boundary, and the env var presumably tightens it further.

Related issues

  • #42844 ("Can no longer tell Claude to change its working directory mid-session") — filed as a behavior regression. This docs issue is complementary: regardless of whether the auto-reset is intended behavior or a regression, the docs should describe it.
  • #42837 (superseded by #42844)
  • #31471 (statusLine cwd reset — separate root cause)

This issue is not asking for the auto-reset behavior to be removed. It's asking for the Bash tool description and public tools-reference docs to accurately describe it, so agents can plan around it correctly.

Requested change

Update the Bash tool description (system prompt) and the public tools-reference docs to say something like:

The working directory persists between commands for paths inside the session's approved working directories. Attempts to cd outside those directories are silently reverted, and a Shell cwd was reset to <dir> notice is appended to the tool result. Shell state (env vars, aliases, functions) does not persist between commands regardless.

Bonus: mention the git -C <path> / make -C <path> pattern as the recommended way to operate on paths inside the workspace -- nested repos or sub-projects.

Environment

  • Claude Code: latest as of 2026-04-08
  • Model: claude-opus-4-6[1m]
  • OS: macOS (Darwin 25.4.0)
  • Shell: zsh

extent analysis

TL;DR

Update the Bash tool description and public tools-reference docs to accurately describe the working directory persistence behavior, including the auto-reset feature for paths outside the session's approved working directories.

Guidance

  • Review the current Bash tool description and public tools-reference docs to identify areas where the documentation is misleading or incomplete.
  • Update the documentation to reflect the actual behavior, including the persistence of the working directory for paths inside the session's approved working directories and the auto-reset feature for paths outside those directories.
  • Consider adding examples or recommendations for using the git -C <path> / make -C <path> pattern to operate on paths inside the workspace, such as nested repos or sub-projects.
  • Verify that the updated documentation accurately reflects the behavior of the Bash tool and provides clear guidance for agents planning multi-step Bash work.

Example

The updated documentation could include a statement like:

"The working directory persists between commands for paths inside the session's approved working directories. Attempts to cd outside those directories are silently reverted, and a Shell cwd was reset to <dir> notice is appended to the tool result."

Notes

The updated documentation should aim to provide a clear and accurate description of the Bash tool's behavior, without implying that the auto-reset feature is a regression or a bug. The goal is to provide agents with a correct understanding of how the tool works, so they can plan their work accordingly.

Recommendation

Apply a workaround by updating the documentation to accurately describe the Bash tool's behavior, including the auto-reset feature. This will help agents plan their work correctly and avoid writing incorrect workarounds.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING