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

Status Closed — not planned
Maintainer reply ✓ Yes — wolffiex
Activity 12 comments · opened Jun 10, 2025 · closed Jan 14, 2026
💡 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: 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.

View original on GitHub ↗

12 Comments

krmmzs · 1 year ago

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 · 1 year ago

If I type:

 SHELL=/bin/bash claude

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

!Image

aparajita · 1 year ago
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'

wolffiex collaborator · 1 year ago

Thanks for the detailed report. This should be fixable

almirsarajcic · 1 year ago

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

SilentChris · 1 year ago

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.

benschumacher · 1 year ago

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.

brandon-fryslie · 10 months ago

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.

github-actions[bot] · 8 months ago

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

adamtaylor13 · 8 months ago

I have this issue, and just use regular bash. I have no idea what the snapshot is supposed to do, so I can't really diagnose, but my errors looked like this:

Successfully activated the macos environment
/Users/adamtaylor/.rvm/rubies/ruby-3.2.2/bin/ruby
/Users/adamtaylor/.tmuxifier/bin/tmuxifier
/Users/adamtaylor/.claude/shell-snapshots/snapshot-bash-1764462593695-n5dfvu.sh: line 271: set: m\^[[01: invalid option name
/Users/adamtaylor/.claude/shell-snapshots/snapshot-bash-1764462593695-n5dfvu.sh: line 271: 31m\^[[Kon\^[[m\^[[Kitor: command not found
/Users/adamtaylor/.claude/shell-snapshots/snapshot-bash-1764462593695-n5dfvu.sh: line 272: set: \^[[01: invalid option name
/Users/adamtaylor/.claude/shell-snapshots/snapshot-bash-1764462593695-n5dfvu.sh: line 272: 31m\^[[Kon\^[[m\^[[Kecmd: command not found

And then when I went to look at the actual snapshot file, it had these options in it:

set -o m^[[01;31m^[[Kon^[[m^[[Kitor
set -o ^[[01;31m^[[Kon^[[m^[[Kecmd

I removed them manually and so far, that's fixed it. Very strange.

EDIT: After a couple days, I've noticed the errors are back. I guess I'm going to try the SHELL fix mentioned above.

github-actions[bot] · 7 months ago

This issue has been automatically closed due to 60 days of inactivity. If you're still experiencing this issue, please open a new issue with updated information.

github-actions[bot] · 7 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.