claude-code - 💡(How to fix) Fix [BUG] Windows: pwsh exited with code 1: The command line is too long — regression starting with Opus 4.7

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…

Error Message

change to the pwsh wrapper (transcript redirection, hook plumbing, error-handling preamble, telemetry, etc.) appears to have pushed the assembled `pwsh -NoProfile -NonInteractive -Command "<wrapped

Error Messages/Logs

Code Example

Command contains malformed syntax that cannot be parsed: pwsh exited with code 1: The command line is too long.
RAW_BUFFERClick to expand / collapse

Preflight Checklist

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

What's Wrong?

Summary

Since switching to Opus 4.7 (claude-opus-4-7[1m]), almost every shell tool call on Windows fails with:

Command contains malformed syntax that cannot be parsed: pwsh exited with code 1: The command line is too long.

This did not happen on prior models against the same machine and same shell. The user-supplied command and the environment are both well within Windows' command-line limits, so the overflow has to be coming from the harness's pwsh-invocation wrapping.

Environment

  • OS: Windows 11 Pro 10.0.26200
  • Shell: PowerShell 7.6.1 (Core)
  • Claude Code version: <FILL IN — output of claude --version>
  • Model: claude-opus-4-7[1m] (Opus 4.7, 1M context)
  • No custom PATH or env bloat (numbers below)

Diagnostic data (collected this session)

PATH chars: 2261 PATH entries: 42 cmd 8191 limit headroom: 5930 CreateProcess 32767 headroom: 30506 Total env block chars: 4255 Env var count: 51

Largest env vars (top 5): Path 2261 PSModulePath 325 PATHEXT 58 JAVA_HOME 56 PROCESSOR_IDENTIFIER 51

Even if the entire env block were re-serialized into argv (it shouldn't be), 4,255 + a typical user command stays well under cmd's 8,191 ceiling.

Repro

Fails on routine, short commands such as trying to test a small dotnet project or build.

The user command itself is only a few hundred characters. The wrapper is therefore contributing several KB of additional content per invocation.

Hypothesis

Node's child_process.spawn on Windows with shell: true routes through cmd.exe, which caps argv at 8,191 chars. Without shell: true, the kernel CreateProcess limit is 32,767 chars. A 4.7-era change to the pwsh wrapper (transcript redirection, hook plumbing, error-handling preamble, telemetry, etc.) appears to have pushed the assembled pwsh -NoProfile -NonInteractive -Command "<wrapped script>" past the 8K boundary on otherwise normal commands.

Suggested fixes (any one of these would resolve it)

  1. Spawn pwsh without shell: true on Windows — moves the limit from 8,191 → 32,767.
  2. Stage the wrapped script to a temp .ps1 and invoke pwsh -File <tmp> instead of -Command "<long string>" — sidesteps argv length entirely.
  3. Audit what 4.7 added to the wrapper preamble; trim or move it into a once-per-session bootstrap rather than a per-call inline.

What "fixed" looks like

Routine short commands (dotnet build, git status, env diagnostics) succeed on Windows under Opus 4.7 with default settings, no PATH pruning required.


Paste-ready. When you fill in the version line and one repro command, it's good to submit.

What Should Happen?

Routine short commands (dotnet build, git status, env diagnostics) succeed on Windows under Opus 4.7 with default settings, no PATH pruning required.

Error Messages/Logs

Command contains malformed syntax that cannot be parsed: pwsh exited with code 1: The command line is too long.

Steps to Reproduce

Windows 11, claude code command line

Repro

Fails on routine, short commands such as trying to test a small dotnet project or build.

Claude Model

Opus

Is this a regression?

Yes, this worked in a previous version

Last Working Version

No response

Claude Code Version

4.6

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

No response

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 [BUG] Windows: pwsh exited with code 1: The command line is too long — regression starting with Opus 4.7