claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[BUG] claude-shell-snapshot-* has a syntax error when using Oh My Zsh

Open aparajita opened this issue 7 months ago • 10 comments

Environment

  • Platform (select one):
    • [x] Anthropic API
    • [ ] AWS Bedrock
    • [ ] Google Vertex AI
    • [ ] Other:
  • Claude CLI version: 1.0.17 (Claude Code)
  • Operating System: macOS 15.5
  • Terminal: iTerm2 v3.5.14

Bug Description

I am using Oh My Zsh. Every time Claude Code is executed (at least in interactive mode), it creates a snapshot of the shell environment at a path like /var/folders/0f/kqpdpv050ggbk_j53dfm84f40000gn/T/claude-shell-snapshot-c773.

Any attempt to execute a bash command from within claude code results in an error like this:

! ls
  ⎿  /var/folders/0f/kqpdpv050ggbk_j53dfm84f40000gn/T/claude-shell-snapshot-29b4:1010: parse error near `()'

The offending line is always this line within the omz_urlencode function:

local mark='_.!~*'()-'

As you can see, that is an unterminated string. The ' in the middle of that string is not escaped. Thus the error on every bash command.

Steps to Reproduce

  1. Install Oh My Zsh
  2. Run claude from the terminal.
  3. Enter ! to enter bash mode and then ls

Expected Behavior

bash commands execute without that parse error.

Actual Behavior

Every bash command executed by claude code results in that parse error.

Additional Context

I asked claude code for a workaround, but ultimately had to disable Oh My Zsh.

aparajita avatar Jun 10 '25 02:06 aparajita

I'm also getting this error, the claude code is executed by creating a bash script. function in /tmp/claude-shell-snapshot-100f:5552:

repeat () {
    while :
    do
        $@ && return
        sleep 3
    done
}

I get:

/tmp/claude-shell-snapshot-0f57:5552: parse error near `()

Image

krmmzs avatar Jun 11 '25 17:06 krmmzs

If I type:

 SHELL=/bin/bash claude

to start claude code, try again same query, everything is back to normal.

Image

krmmzs avatar Jun 11 '25 17:06 krmmzs

If I type:

SHELL=/bin/bash claude to start claude code, try again same query, everything is back to normal.

Brilliant! A good workaround. For those using this technique, you'll probably want to add this alias:

alias claude='SHELL=/bin/bash claude'

aparajita avatar Jun 11 '25 18:06 aparajita

Thanks for the detailed report. This should be fixable

wolffiex avatar Jun 18 '25 00:06 wolffiex

Thanks guys. This helped me, even though I didn't have the same error message, but it was still due to not using bash. https://github.com/anthropics/claude-code/issues/2139#issuecomment-2994060105

almirsarajcic avatar Jun 22 '25 09:06 almirsarajcic

This happens to me as well, running zsh on Mac, with Oh My Zsh installed. The error frequently (always) seems to be at that repeat () function definition. I wonder if it's conflicting with something setup by OMZ?

Would love to see this fixed, but the workaround helps for now.

SilentChris avatar Aug 01 '25 22:08 SilentChris

fwiw- i see this issue as well, and i don't use Oh My Zsh. i believe this is just a shell incompatibility because Zsh has a shell built-in repeat command, whereas Bash does not.

benschumacher avatar Aug 08 '25 15:08 benschumacher

This is a problem with a zsh plugin, not zsh itself. I have this in my zshrc to prevent claude from loading any zsh plugins or p10k:

is_claude() { [[ -n "${CLAUDECODE}" ]] && return 0 || return 1 }
not_claude() { ! is_claude && return 0 || return 1 }

# We need to be able to define a set of plugins to load for human vs ai users
if not_claude; then
  source ~/.rad-shell/rad-init.zsh
  [[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
fi

I have noticed no problems with missing tools (they are set up in my zsh plugins) , so presumably claude is using the inherited $PATH from the environment anyway.

Using bash was not ideal for me because there is configuration in my zshrc I want claude to have, and I don't feel like maintaining a basic as well.

brandon-fryslie avatar Oct 21 '25 07:10 brandon-fryslie