anthropics / anthropics/claude-code

Windows: Bash tool permanently broken in long-lived sessions - inlined shell snapshot exceeds command-line length and is truncated

Open
#88,311 0 comments 0 reactions 0 assignees View on GitHub
area:bash bug has repro platform:vscode platform:windows
Dominant language
Python
Stars
145k
Forks
23.1k
PR merge metrics
PR metrics pending

Description

# Bug report — para /bug o github.com/anthropics/claude-code/issues

**Title:** Windows: Bash tool permanently broken in long-lived sessions — inlined shell snapshot + wrapper exceeds command-line length and is truncated (every command fails with "unexpected EOF")

**Environment:** Claude Code 2.1.233 (VS Code extension), Windows 11 Home 10.0.26200, Git Bash (msys), ~17 plugins enabled, session resumed multiple times over several days.

**Symptom:** Every Bash tool call fails, including `true` and `pwd`. Errors rotate between:

```
/usr/bin/bash: -c: line 67: unexpected EOF while looking for matching `''
/usr/bin/bash: line 67: /dev/n: No such file or directory
/usr/bin/bash: line 67: p: command not found
```

The visible fragment shows the harness wrapper truncated mid-token (e.g. `eval 'git status' < /dev/null && pwd -P >| '` — the cwd-file path is cut off). The cut point moves 1:1 with the length of the user command, indicating a fixed total-length cap on the composed `bash -c` string.

**Root cause (diagnosed):**
1. The Bash tool composes ONE `bash -c ""` that INLINES the shell snapshot (~45 lines; on this machine the `export PATH` line alone is ~4.5KB due to duplicated Windows PATH blocks + one `bin` dir per enabled plugin) plus the harness prologue/epilogue. Error line numbers (64-71) match snapshot lines + wrapper lines.
2. When the environment grows (plugins loaded at resume, duplicated PATH), the composed string crosses a Windows command-line length limit and is silently truncated → unparseable script → every call fails.
3. The composed wrapper appears to be CACHED per conversation: editing/shrinking the files in `~/.claude/shell-snapshots/` mid-session has no effect (error stays at the same line even after replacing the active snapshot with a 3-line file). Only a brand-new conversation regenerates it.
4. Subagents spawned by the broken session inherit the same broken wrapper; retries never help (deterministic).

**Repro sketch:** Windows + many plugins + duplicated PATH (launch VS Code from an already-extended shell) → long-lived conversation with several resumes → Bash calls degrade from "long commands fail" to "everything fails".

**Suggested fix:** write the composed script to a temp file and execute `bash ` (or source the snapshot by path) instead of inlining everything into `-c` — removes the length ceiling entirely. Related: #55671 (command line too long on Windows), #31437 (snapshot inlining overhead).

**Impact:** total loss of shell for the session (file tools keep working); user-visible as "Claude can't run any command anymore".

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at the Bash tool entry point that constructs the Windows `bash -c` wrapper, and inspect the files under `~/.claude/shell-snapshots/` involved in the cached snapshot. Reproduce with a long PATH and multiple plugins, then verify that executing the composed script from a temporary file avoids truncation and that short commands such as `true` and `pwd` succeed in a resumed session.

Written by the indexing model from the issue text.

Assessment

Tech stack
bash, python
Domain
cli, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.