claude-code - 💡(How to fix) Fix Opus 4.7 defaults to Bash tool on Windows despite CLAUDE_CODE_USE_POWERSHELL_TOOL=1; system prompt injects 'Shell: bash' [1 comments, 2 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#51788Fetched 2026-04-22 07:52:50
View on GitHub
Comments
1
Participants
2
Timeline
6
Reactions
0
Author
Timeline (top)
labeled ×4commented ×1cross-referenced ×1

On Windows, with CLAUDE_CODE_USE_POWERSHELL_TOOL=1 set and explicit CLAUDE.md directives to prefer the PowerShell tool, Opus 4.7 still reaches for the Bash tool by default for command execution. This is a behavioral regression compared to Opus 4.6, which followed CLAUDE.md shell preferences more reliably.

Root Cause

Observed diagnosis (root cause)

Fix Action

Workaround

Users can block the Bash tool via settings.json permissions denylist, but this breaks legitimate Bash-only use cases (bashrc-defined functions, POSIX-only scripts). A scalpel workaround doesn't exist today.

RAW_BUFFERClick to expand / collapse

Summary

On Windows, with CLAUDE_CODE_USE_POWERSHELL_TOOL=1 set and explicit CLAUDE.md directives to prefer the PowerShell tool, Opus 4.7 still reaches for the Bash tool by default for command execution. This is a behavioral regression compared to Opus 4.6, which followed CLAUDE.md shell preferences more reliably.

Environment

  • OS: Windows 11 Enterprise (native, no WSL)
  • Claude Code: current stable (v2.1.x series)
  • Model: claude-opus-4-7 (1M context)
  • CLAUDE_CODE_USE_POWERSHELL_TOOL: set to 1 in shell profile (process-level, confirmed)
  • CLAUDE.md: contains explicit directive: "Always use the PowerShell tool for command execution, not the Bash tool." with documented exceptions (agent-browser, venv activation, .sh scripts)
  • Both Bash and PowerShell tools are registered simultaneously.

Observed diagnosis (root cause)

Inspecting the system prompt delivered to the model on Windows, the harness injects this line verbatim:

Shell: bash (use Unix shell syntax, not Windows — e.g., /dev/null not NUL, forward slashes in paths)

This line is injected even when CLAUDE_CODE_USE_POWERSHELL_TOOL=1 is set and the PowerShell tool is registered. It creates a direct conflict:

  • System prompt declares the shell as bash (highest instruction weight).
  • CLAUDE.md declares PowerShell as the preferred tool (lower weight — injected as user context).

Opus 4.7 — which multiple public writeups describe as following instructions more literally than 4.6 — honors the system prompt's shell declaration over CLAUDE.md's preferences. Opus 4.6 was "looser" and inferred intent from CLAUDE.md more often; 4.7's stricter instruction-following amplifies this existing conflict rather than resolving it.

Why this is a regression, not just an existing bug

This has been reported before (#6453, #45831, #28670, #15471), but the severity is materially worse on 4.7. Users who had working 4.6-era CLAUDE.md configurations are experiencing sudden drift to Bash tool use without changing anything on their end. The model isn't "wrong" — the harness is sending conflicting signals and 4.7 resolves the conflict differently than 4.6 did.

Proposed fix (harness-side, not model-side)

When CLAUDE_CODE_USE_POWERSHELL_TOOL=1 is set on Windows, the system prompt should either:

  1. Relabel the shell line to Shell: PowerShell (use PowerShell syntax...), OR
  2. Omit the Shell: line entirely and let the tool list + CLAUDE.md speak for themselves, OR
  3. Inject Shell: PowerShell with a one-line exceptions note pointing users to use the Bash tool for POSIX-requiring cases.

Option 1 is the cleanest — it mirrors the tool that's actually registered.

Additionally, consider unregistering the Bash tool entirely when the PowerShell tool is active (gated by a separate env var like CLAUDE_CODE_DISABLE_BASH_TOOL=1 for users who want hard enforcement).

Workaround

Users can block the Bash tool via settings.json permissions denylist, but this breaks legitimate Bash-only use cases (bashrc-defined functions, POSIX-only scripts). A scalpel workaround doesn't exist today.

Related issues

  • #6453 — "CC attempts to use Bash in a Windows PowerShell environment despite all prompts otherwise"
  • #45831 — "Claude defaults to bash/Unix syntax on Windows instead of PowerShell"
  • #28670 — "Claude Code repeatedly uses Bash syntax (extglob) on Windows PowerShell and fails to adapt"
  • #15471 — Windows shell compatibility

This issue adds: confirmation that the behavior worsened with the 4.7 release and a specific root-cause identification (the Shell: bash system prompt line overriding CLAUDE.md).

extent analysis

TL;DR

The most likely fix is to modify the system prompt to reflect the preferred shell when CLAUDE_CODE_USE_POWERSHELL_TOOL=1 is set, such as relabeling the shell line to Shell: PowerShell.

Guidance

  • Verify that the CLAUDE_CODE_USE_POWERSHELL_TOOL environment variable is correctly set to 1 in the shell profile.
  • Check the system prompt delivered to the model for the conflicting Shell: bash line and consider modifying it to prefer PowerShell.
  • Evaluate the proposed fix options: relabeling the shell line, omitting the Shell: line, or injecting a Shell: PowerShell line with exceptions.
  • Consider unregistering the Bash tool when the PowerShell tool is active using a separate environment variable like CLAUDE_CODE_DISABLE_BASH_TOOL=1.

Example

No code snippet is provided as the issue is related to environment variables and system prompts.

Notes

The issue is specific to Windows and Opus 4.7, and the proposed fixes aim to resolve the conflict between the system prompt and CLAUDE.md preferences. The severity of the issue has increased with the 4.7 release, causing sudden drift to Bash tool use for users with existing CLAUDE.md configurations.

Recommendation

Apply the proposed fix to modify the system prompt to reflect the preferred shell when CLAUDE_CODE_USE_POWERSHELL_TOOL=1 is set, as this is the most direct solution to the identified root cause.

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

claude-code - 💡(How to fix) Fix Opus 4.7 defaults to Bash tool on Windows despite CLAUDE_CODE_USE_POWERSHELL_TOOL=1; system prompt injects 'Shell: bash' [1 comments, 2 participants]