[BUG] Windows: pwsh exited with code 1: The command line is too long — regression starting with Opus 4.7
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?
## 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 ofclaude --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 past the 8K boundary on otherwise normal commands.
script>"
## Suggested fixes (any one of these would resolve it)
- Spawn pwsh without
shell: trueon Windows — moves the limit from 8,191 → 32,767. - Stage the wrapped script to a temp
.ps1and invokepwsh -File <tmp>instead of-Command "<long string>"— sidesteps argv length entirely. - 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_
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗