[Bug] Windows/Git Bash: corrupted shell snapshot (serialized git-completion functions) makes every Bash tool call exit 127 with no output

Status Open
Reported on v2.1.251
Maintainer reply None cached
Activity 0 comments · opened Aug 31, 2026

Summary

On Windows with Git Bash, the Bash tool returns Error: Exit code 127 with empty stdout and stderr for every command — including shell builtins (pwd, type echo) and absolute paths to real binaries.

Root cause (verified locally): the shell snapshot file generated under ~/.claude/shell-snapshots/ is corrupted, and every Bash tool invocation sources that snapshot before running the user command. A source-time syntax error kills the entire bash -c script, and bash exits with 127 — which is exactly what the tool reports. The snapshot is generated successfully every session (bash is found and launched), it just can't be parsed.

The corrupted content is the serialized git-completion functions that Git Bash loads via /etc/profile.d/git-prompt.sh → mingw64/share/git/completion/git-completion.bash.

Environment

  • Claude Code 2.1.251 (npm native binary, win32-x64)
  • Windows 11, build 10.0.26200
  • Git for Windows 2.53.0.windows.1 — GNU bash 5.2.37(1)-release (MSYS2), installed at a non-default location (D:\Program Files\Git)
  • Windows user profile path contains non-ASCII (Chinese) characters (C:\Users\<redacted>)
  • CLAUDE_CODE_GIT_BASH_PATH set and valid

Symptoms

  • Every Bash tool call fails: Exit code 127, no output at all
  • Builtins and /usr/bin/... absolute paths fail identically
  • All other tools (Read / Write / WebFetch / MCP) work fine
  • Interactive Git Bash on the same machine works normally
  • A shell snapshot file is written on every session start (so the shell is launched), but every subsequent command dies at snapshot-source time

Evidence

  1. bash -n on the generated snapshot fails reproducibly:
$ bash -n ~/.claude/shell-snapshots/snapshot-bash-*.sh
snapshot-bash-....sh: line 9: syntax error near unexpected token `('
snapshot-bash-....sh: line 9: `eval $'__git_complete_config_variable_value () \n{ \n ... }' > /dev/null 2>&1'
  1. Sourcing it reproduces the tool's failure byte-for-byte (exit 127, no stdout):
$ bash -c "source ~/.claude/shell-snapshots/snapshot-bash-*.sh; echo ok"
<same syntax error>
$ echo $?
127
  1. Bisecting the file line by line shows the corruption is structural, not a quoting quirk in one function:
  • Line 1 (export PATH='...') parses fine on its own
  • Line 2 fails with unexpected EOF while looking for matching '"', and line 2 begins mid-token (ord" in \n ...) — the head of that eval $'...' line is missing entirely
  • The file tail ends with a dangling comment (# Shadow pkill to refuse patterns matching the CLI process) whose function body is absent
  1. The broken lines are exactly the function-replay entries of the form eval $'__git_* () \n{ \n ... }' > /dev/null 2>&1 (the format used for "replaying snapshot functions").
  2. Snapshots regenerated across sessions on the same day are byte-identical (65284 bytes both times) → deterministic writer bug, not flakiness. An older snapshot from a previous version (2.1.226, 84178 bytes) is also syntactically broken, just at a different offset (line 1062: unexpected EOF while looking for matching '), so the writer has been producing invalid files here for a while.

Workaround (verified)

Prevent git-completion from being loaded into the shell that Claude Code snapshots, so the snapshot only contains the PATH export and small aliases:

# either rename the completion script...
Rename-Item "Git\mingw64\share\git\completion\git-completion.bash" "git-completion.bash.disabled"
# ...or guard the load in Git\etc\profile.d\git-prompt.sh:
#   test -f "$COMPLETION_PATH/git-completion.bash" && . "$COMPLETION_PATH/git-completion.bash"
# (optionally also: [ -z "$CLAUDECODE" ] to keep completion for interactive use)

Then delete ~/.claude/shell-snapshots/* and restart Claude Code. On 2.1.251 this fully restores the Bash tool: the new snapshot is small, valid, and echo ok → ok.

Side effect: git TAB completion in interactive Git Bash is lost while the workaround is in place.

Related issues

  • #15128 — snapshot exports empty PATH (different corruption of the same file family)
  • #16377 — Windows snapshot generation fixes
  • #61293 — 2.1.147 regression (fixed in 2.1.148, different cause)

Happy to provide the corrupted snapshot file if useful (contains nothing sensitive beyond PATH entries; username redacted).

View original on GitHub ↗