Shell snapshot generates invalid bash: empty if/then/fi when rg is already installed

Resolved 💬 4 comments Opened Mar 7, 2026 by sweetrb Closed Apr 5, 2026

Description

On Windows (MSYS2 bash), Claude Code's shell snapshot generates a syntactically invalid bash script when rg (ripgrep) is already installed on the system independently (e.g., via Scoop).

Environment

  • Claude Code v2.1.71
  • Windows 11, MSYS2 /usr/bin/bash
  • ripgrep installed via Scoop (/c/Users/rob/scoop/shims/rg)

Root Cause

Claude Code creates an rg shim function (multi-call binary wrapper) and a conditional block in the shell snapshot to check if rg is available. When rg is already installed, the function goes outside the if block and the if block body is left empty:

  function rg {
  if [[ "$OSTYPE" == "msys" ]] || ...; then
    ARGV0=rg 'C:\Users\rob\.local\bin\claude.exe' "$@"
  ...
  fi
}
# Check for rg availability
if ! (unalias rg 2>/dev/null; command -v rg) >/dev/null 2>&1; then
fi
export PATH=$PATH

An empty then/fi block (if ...; then\nfi with no body) is a bash syntax error:

syntax error near unexpected token `fi'

When rg is NOT available, the shim function goes inside the if block, making it syntactically valid.

Impact

Every shell command in Claude Code emits the syntax error. Additionally, the error during snapshot sourcing can corrupt alias parsing — aliases defined before the error point are lost.

Reproduction

  1. Install ripgrep independently: scoop install ripgrep
  2. Start a Claude Code session
  3. Run any command — observe the unexpected token 'fi' error from the snapshot

Suggested Fix

Either:

  • Add a no-op (:) inside the empty if block: if ...; then\n:\nfi
  • Skip the if block entirely when the body would be empty
  • Use declare -f canonical format instead of raw function source for snapshot capture

Workaround

Uninstall ripgrep from Scoop so Claude Code's if block has a body (the shim function). Keep a standalone rg.exe in a bin directory for non-Claude shells.

View original on GitHub ↗

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