Fix Claude Code git show --no-stat Error

Claude Code frequently runs git show HEAD --no-stat, but --no-stat is not a valid git-show flag. This causes exit code 128 errors and wastes context on retries.

Known bug since v2.0.58 — still present in v2.1.87

44 reactions on #13071. Adding --no-stat to CLAUDE.md doesn't help — Claude ignores it.

The Error

$ git show HEAD --no-stat
fatal: unrecognized argument: --no-stat

Each failure burns context tokens on the error message and Claude's retry attempt.

The Fix: PreToolUse Hook

A PreToolUse hook intercepts the command before execution and strips the invalid flag via updatedInput. Claude never sees the error.

git-show-flag-sanitizer.sh:

#!/bin/bash
# TRIGGER: PreToolUse | MATCHER: "Bash"
INPUT=$(cat)
COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command // empty')
[ -z "$COMMAND" ] && exit 0

case "$COMMAND" in
  *git\ show*--no-stat*) ;;
  *) exit 0 ;;
esac

NEW_COMMAND=$(echo "$COMMAND" | sed 's/ --no-stat//' | sed 's/  */ /g')

jq -n --arg cmd "$NEW_COMMAND" '{
  hookSpecificOutput: {
    hookEventName: "PreToolUse",
    permissionDecision: "allow",
    updatedInput: { command: $cmd }
  }
}'

Install

npx cc-safe-setup --install-example git-show-flag-sanitizer

Or add manually to .claude/settings.json:

{
  "hooks": {
    "PreToolUse": [{
      "matcher": "Bash",
      "hooks": [{
        "type": "command",
        "command": "bash /path/to/git-show-flag-sanitizer.sh"
      }]
    }]
  }
}

Install All Safety Hooks

npx cc-safe-setup

8 safety hooks + 655 examples. 9,200+ tests.

cc-safe-setup · 667 hooks · 9,200+ tests · GitHub