Stop Claude Code from Retrying Denied Commands

You say "No" to a command. Claude runs it anyway. Then asks for the next command. The only way to stop it is Ctrl+C.

This is a known bug. A PreToolUse hook can enforce the denial at the process level.

The Fix

denied-action-retry-guard.sh — tracks denied commands and auto-blocks retries:

#!/bin/bash
# TRIGGER: PreToolUse | MATCHER: "Bash|Edit|Write"
INPUT=$(cat)
TOOL=$(echo "$INPUT" | jq -r '.tool_name // empty')
COMMAND=$(case "$TOOL" in
  Bash) echo "$INPUT" | jq -r '.tool_input.command // empty' ;;
  *) echo "$INPUT" | jq -r '.tool_input.file_path // empty' ;;
esac)
[ -z "$COMMAND" ] && exit 0

STATE="/tmp/cc-denied-$$"
SIG=$(echo "$TOOL:$COMMAND" | md5sum | cut -d' ' -f1)

if [ -f "$STATE" ] && grep -q "$SIG" "$STATE"; then
    echo "BLOCKED: Previously denied operation" >&2
    exit 2
fi
exit 0

Install All Safety Hooks

npx cc-safe-setup

591 hooks. 8,872 tests.

cc-safe-setup · 591 hooks · 8,872 tests · GitHub