[BUG] Bash commands fail with exit code 1 and no output (empty rg block in shell snapshot)

Resolved 💬 3 comments Opened Mar 17, 2026 by yki-t Closed Mar 17, 2026

Preflight Checklist

  • [x] I've searched existing issues and this specific root cause is not reported
  • [x] This is a single bug report
  • [x] I'm using the latest version of Claude Code

What's Wrong?

The Bash tool fails completely — every command returns exit code 1 with no output.

● Bash(echo ok)
  ⎿  Error: Exit code 1

● Bash(ls)
  ⎿  Error: Exit code 2

● Bash(whoami)
  ⎿  Error: Exit code 1

This affects all Bash tool invocations. Other tools (Read, Glob, Grep) work fine.

Troubleshooting attempted:

  • Enabled/disabled hooks → no effect
  • dangerouslyDisableSandbox: true → no effect
  • Commented out Nix blocks in /etc/zshrc, /etc/bash.bashrc → no effect
  • New shell session + new Claude Code session → no effect

Expected Behavior

echo ok should output ok with exit code 0.

Error Messages / Logs

Debug log (claude --debug) shows:

[DEBUG] Creating shell snapshot for zsh (/bin/zsh)
[DEBUG] Shell snapshot created successfully (20946 bytes)
[DEBUG] Spawning shell without login (-l flag skipped)
[DEBUG] Bash tool error (137ms): Shell command failed

The snapshot is created successfully, but the command fails in ~5ms after spawn.

Root Cause

The generated snapshot (~/.claude/shell-snapshots/snapshot-zsh-*.sh) contains an empty if-then-fi block:

# Check for rg availability
if ! (unalias rg 2>/dev/null; command -v rg) >/dev/null 2>&1; then
fi

In zsh, an empty then clause is a parse error:

% if true; then
then> fi
zsh: parse error near 'fi'

Sourcing this snapshot fails, so no command can execute.

Why this happens

In v2.1.71, the rg fallback function was always included:

if ! (unalias rg 2>/dev/null; command -v rg) >/dev/null 2>&1; then
  function rg {
    ARGV0=rg /home/user/.local/share/claude/versions/2.1.71 "$@"
    ...
  }
fi

In v2.1.77, when system rg is already available, the fallback function is omitted — but the if-then-fi structure is still emitted with an empty body.

Suggested fix

Either:

  • Omit the entire if-then-fi block when rg is available
  • Add a no-op (:) inside the empty then block

Reproduction Steps

  1. Use zsh as default shell
  2. Have ripgrep installed system-wide (e.g. /usr/bin/rg)
  3. Start Claude Code v2.1.77
  4. Run any Bash tool command

Environment

| Detail | Value |
|--------|-------|
| Claude Code Version | 2.1.77 |
| Shell | zsh 5.9 (/bin/zsh) |
| OS | Arch Linux (kernel 6.18.9) |
| ripgrep | /usr/bin/rg (system-installed) |
| Platform | Claude Max (CLI) |

Related Issues

  • #4999 — Malformed rg alias in snapshot (Windows/zsh)
  • #9670 — Snapshot export PATH syntax error

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗