[BUG] claude-shell-snapshot-* has a syntax error when using Oh My Zsh
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
- Install Oh My Zsh
- Run
claudefrom the terminal. - Enter
!to enter bash mode and thenls
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.
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 `()
If I type:
SHELL=/bin/bash claude
to start claude code, try again same query, everything is back to normal.
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'
Thanks for the detailed report. This should be fixable
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
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.
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.
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.