[BUG] Git Commands Fail with error: claude-shell-snapshot-4824:1716: parse error near ()'

Resolved 💬 23 comments Opened Apr 14, 2025 by cromulus Closed Apr 21, 2025
💡 Likely answer: A maintainer (wolffiex, collaborator) responded on this thread — see the highlighted reply below.

Environment

  • Platform (select one):
  • [X] Anthropic API
  • [ ] AWS Bedrock
  • [ ] Google Vertex AI
  • [ ] Other: <!-- specify -->
  • Claude CLI version: 0.2.69 (Claude Code)
  • Operating System: Mac OSX 15.3.2
  • Terminal: iTerm2

Bug Description

After a recent update, Claude Code is no longer able to execute git commands. Constantly get this error:

Bash(git diff master)…
  ⎿  /var/folders/yq/fkn_qw293fgfr3vz7jmnjxpw0000gn/T/claude-shell-snapshot-4824:1716: defining function based on alias `run-help'
     /var/folders/yq/fkn_qw293fgfr3vz7jmnjxpw0000gn/T/claude-shell-snapshot-4824:1716: parse error near `()'

Steps to Reproduce

  1. Open Claude in a git repo
  2. Ask Claude to perform a git command
  3. Receive Error

Expected Behavior

I expect Claude to be able to perform git commands.

Actual Behavior

Error out, received the errors above.

Additional Context

  • git version 2.49.0
  • zsh 5.9 (arm-apple-darwin21.3.0)

This may be occurring with other commands, I just happened to notice it with git.
Claude can read files, and edit files just fine though.

View original on GitHub ↗

23 Comments

cromulus · 1 year ago

Additional details:
Environment Info

  • Platform: macos
  • Terminal: iTerm.app
  • Version: 0.2.69
  • Feedback ID: 7ce65329-e251-4aad-aa7d-a89785277aa2

Errors

[{"error":"ShellError: Shell command failed\n    at Object.call (file:///Users/bill/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:1134:1010)\n    at async cc5 (file:///Users/bill/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:1570:4980)\n    at async O61 (file:///Users/bill/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:1570:3472)","timestamp":"2025-04-14T07:54:22.157Z"},{"error":"ShellError: Shell command failed\n    at Object.call (file:///Users/bill/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:1134:1010)\n    at async cc5 (file:///Users/bill/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:1570:4980)\n    at async O61 (file:///Users/bill/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:1570:3472)","timestamp":"2025-04-14T07:54:22.164Z"},{"error":"Error: Tool error\n    at Object.call (file:///Users/bill/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:1701:5980)\n    at async cc5 (file:///Users/bill/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:1570:4980)\n    at async O61 (file:///Users/bill/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:1570:3472)","timestamp":"2025-04-14T07:54:22.171Z"}]
codelahoma · 1 year ago

I believe it's the Bash tool, not just git commands:

```> What directory are we in?

⏺ Bash(pwd)…
  ⎿  /var/folders/m5/s6x3rp3d4xx83l4wx1rmg0gc0000gn/T/claude-shell-snapshot-943f:4277: defining function based on alias run-help'
/var/folders/m5/s6x3rp3d4xx83l4wx1rmg0gc0000gn/T/claude-shell-snapshot-943f:4277: parse error near
()'

⏺ Bash(cd /Users/rodk/work/atlas-up-ai && pwd)…
  ⎿  /var/folders/m5/s6x3rp3d4xx83l4wx1rmg0gc0000gn/T/claude-shell-snapshot-943f:4277: defining function based on alias run-help'
/var/folders/m5/s6x3rp3d4xx83l4wx1rmg0gc0000gn/T/claude-shell-snapshot-943f:4277: parse error near
()'

codelahoma · 1 year ago

Rolling back to v0.2.68 eliminated the issue.

samking · 1 year ago

This issue started happening for me today as well. It isn't just git, though -- for me it started happening when running Bash(yarn prettier --write filename) .

paskal · 1 year ago

With SHELL=/bin/bash claude the issue doesn't reproduce, but does with zsh + zprezto, and the problem is definitely with source "${ZDOTDIR:-$HOME}/.zprezto/init.zsh" in my .zshrc file, as if I comment it out, everything starting working again after claude code restart.

In init.sh, (( $+aliases[run-help] )) && unalias run-help && autoload -Uz run-help is the line which causes trouble for Claude.

In my zsh with zprezto loaded as usual:

$ which run-help
run-help () {
        # undefined
        builtin autoload -XUz
}

This is precisely what is written at the problematic line in claude-shell-snapshot file it mentions as problematic, it chokes on that function.

paskal · 1 year ago

Simple workaround for now, in your .zshrc find init.zsh invokation and replace it with:

if [[ -s "${ZDOTDIR:-$HOME}/.zprezto/init.zsh" ]]; then
  if [[ -z "${CLAUDECODE}" ]]; then
    source "${ZDOTDIR:-$HOME}/.zprezto/init.zsh"
  fi
fi

I happen to find that CLAUDECODE is distinct env variable set during run of the shell commands by Claude Code:

! env | grep -i claude
  ⎿  CLAUDECODE=1
wolffiex collaborator · 1 year ago

thanks for this detailed report! would you mind including the complete contents of your /var/folders/yq/fkn_qw293fgfr3vz7jmnjxpw0000gn/T/claude-shell-snapshot-4824:1716 or similar?
This is the new shell implementation we shipped last friday.

cpjk · 1 year ago
Simple workaround for now, in your .zshrc find init.zsh invokation and replace it with: `` if [[ -s "${ZDOTDIR:-$HOME}/.zprezto/init.zsh" ]]; then if [[ -z "${CLAUDECODE}" ]]; then source "${ZDOTDIR:-$HOME}/.zprezto/init.zsh" fi fi ` I happen to find that CLAUDECODE is distinct env variable set during run of the shell commands by Claude Code: ` ! env | grep -i claude   ⎿  CLAUDECODE=1 ``

For posterity, this solution worked for me 👍🏼 🙏🏼

codelahoma · 1 year ago

I am not using zprezto, but have this issue. Setting SHELL=/bin/bash claude resolves it, though, so it's most likely because of _something_ in my .zshrc. The issue is still present in 0.2.70.

wolffiex collaborator · 1 year ago

if anyone can share the contents of their snapshot file (looks like /var/folders/m5/s6x3rp3d4xx83l4wx1rmg0gc0000gn/T/claude-shell-snapshot-943f) that would be super helpful

cooper-watcha · 1 year ago

Hi everyone. In my case, I'm experiencing a slightly different error message compared to yours, but it appears to be related to the same issue.

I'm using bash shell with iTerm on macOS, and here's what I'm seeing:

⏺ Bash(git diff --cached)…
  ⎿  /var/folders/4n/fj8fctyn4hs3q97mlmxff1zw0000gn/T/claude-shell-snapshot-c97a: line 451: syntax error near unexpected token `|'
     /var/folders/4n/fj8fctyn4hs3q97mlmxff1zw0000gn/T/claude-shell-snapshot-c97a: line 451: ` | sed 's/\\\[\\033/g' | sed 's/\\\]//g''
````

[claude-shell-snapshot-c97a.txt](https://github.com/user-attachments/files/19766941/claude-shell-snapshot-c97a.txt)

@wolffiex Here's my snapshot file for your reference. (FYI: This is excluding the alias command section)
paskal · 1 year ago

I hope I won't regret it.

claude-shell-snapshot-5256.txt

GandalfTheSysAdmin · 1 year ago

I’m running into the same issue. Setting SHELL=/bin/bash claude, as @paskal suggested, worked as a temporary workaround for me too.

siovene · 1 year ago

I wanted to contribute by adding that the problem happens on bash for me. SHELL=/bin/bash claude doesn't help.

git_prompt_examples () 
{ 
    cat  <<EOF
These are examples of the git prompt:

  [${GIT_PROMPT_BRANCH}master${ResetColor}${GIT_PROMPT_REMOTE}↑·3${ResetColor}|${GIT_PROMPT_CHANGED}1${ResetColor}]  - on branch "master", ahead of remote by 3 commits, 1
                    file changed but not staged

  [${GIT_PROMPT_BRANCH}status${ResetColor}|${GIT_PROMPT_STAGED}2${ResetColor}]     - on branch "status", 2 files staged

  [${GIT_PROMPT_BRANCH}master${ResetColor}|${GIT_PROMPT_CHANGED}7${GIT_PROMPT_UNTRACKED}${ResetColor}]    - on branch "master", 7 files changed, some files untracked

  [${GIT_PROMPT_BRANCH}master${ResetColor}|${GIT_PROMPT_CONFLICTS}2${GIT_PROMPT_CHANGED}3${ResetColor}]   - on branch "master", 2 conflicts, 3 files changed

  [${GIT_PROMPT_BRANCH}master${ResetColor}|${GIT_PROMPT_STASHED}2${ResetColor}]     - on branch "master", 2 stash entries

  [${GIT_PROMPT_BRANCH}experimental${ResetColor}${GIT_PROMPT_REMOTE}↓·2↑·3${ResetColor}|${GIT_PROMPT_CLEAN}${ResetColor}]
                  -  on branch "experimental"; your branch has diverged
                     by 3 commits, remote by 2 commits; the repository is
                     otherwise clean

  [${GIT_PROMPT_BRANCH}:70c2952${ResetColor}|${GIT_PROMPT_CLEAN}${ResetColor}]    - not on any branch; parent commit has hash "70c2952"; the
                    repository is otherwise clean
EOF
 | sed 's/\\\[\\033/ESC/g' | sed 's/\\\]//g'
}

The problematic line seems to be | sed 's/\\\[\\033/ESC/g' | sed 's/\\\]//g' bear the end of that snippet in /var/folders/q1/7vbmgf455wldzb2svh1q5z440000gn/T/claude-shell-snapshot-1e17.

wolffiex collaborator · 1 year ago

For folks where switching to bash helps, this is probably because the issue is with your zshrc. The alternative is to condition problematic parts of your .zshrc on
if [[ -z "${CLAUDECODE}" ]]; then

This will be set when Claude Code is sourcing your config and presumably not set otherwise

wolffiex collaborator · 1 year ago

@siovene can you please share the original definition of git_prompt_examples from your .bashrc?

wolffiex collaborator · 1 year ago

ok we have a fix for "defining function based on alias" that should go out tomorrow
there was an additional issue with rc files that trapped exit signals which should also be fixed
an example of a bash function that we are not capturing correctly would be super helpful

siovene · 1 year ago

@wolffiex the issue was this in my .bashprofile:

if [ -f "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh" ]; then
    export GIT_PROMPT_SHOW_UNTRACKED_FILES=no
    source "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh"
fi

Solved by using if [[ -z "${CLAUDECODE}" ]]; then to exclude it:

if [ -f "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh" ]; then
    if [[ -z "${CLAUDECODE}" ]]; then
        export GIT_PROMPT_SHOW_UNTRACKED_FILES=no
        source "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh"
    fi
fi
wolffiex collaborator · 1 year ago

thanks for the reference @siovene ! I think I have this fix for this. Should roll out on Monday at the latest.

paskal · 1 year ago

Works in 0.2.76 for me.

wolffiex collaborator · 1 year ago

ok I think this should be fixed with 0.2.76

vincentbernat · 1 year ago

Looking at #1849, it may be difficult to fix all the issues. For example, in my case, I have in the snapshot:

alias -- '='='noglob qalc'

It's not possible to declare = as an alias. In my original zshrc, I use a workaround:

aliases[=]='noglob qalc'

I don't mind Claude not being able to run commands exactly as I do. Most of my zshrc aliases are sugarcoat. I suppose I could put a test on CLAUDECODE somewhere, but I suppose we would be many stubbling into such problems. Could we just opt-out of this behavior?

github-actions[bot] · 11 months ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.