cc-safe-setup 29.6.4 → 29.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -117,7 +117,7 @@ Install any of these: `npx cc-safe-setup --install-example <name>`
117
117
  | `--scan [--apply]` | Tech stack detection |
118
118
  | `--export / --import` | Team config sharing |
119
119
  | `--verify` | Test each hook |
120
- | `--install-example <name>` | Install from 412 examples |
120
+ | `--install-example <name>` | Install from 413 examples |
121
121
  | `--examples [filter]` | Browse examples by keyword |
122
122
  | `--full` | All-in-one setup |
123
123
  | `--status` | Check installed hooks |
@@ -0,0 +1,49 @@
1
+ #!/bin/bash
2
+ # ================================================================
3
+ # consecutive-error-breaker.sh — Stop after N consecutive errors
4
+ # ================================================================
5
+ # PURPOSE:
6
+ # When Claude Code hits the same error repeatedly (e.g., build
7
+ # failure, test failure, API error), it often keeps retrying
8
+ # the same approach. This hook counts consecutive non-zero
9
+ # exit codes and blocks further tool calls after a threshold.
10
+ #
11
+ # TRIGGER: PostToolUse
12
+ # MATCHER: "Bash"
13
+ #
14
+ # CONFIGURATION:
15
+ # CC_ERROR_STREAK_MAX=5 (max consecutive errors, default: 5)
16
+ #
17
+ # See: https://github.com/anthropics/claude-code/issues/38239
18
+ # ================================================================
19
+
20
+ INPUT=$(cat)
21
+ EXIT_CODE=$(echo "$INPUT" | jq -r '.tool_result.exit_code // "0"' 2>/dev/null)
22
+ STDOUT=$(echo "$INPUT" | jq -r '.tool_result.stdout // empty' 2>/dev/null)
23
+ STDERR=$(echo "$INPUT" | jq -r '.tool_result.stderr // empty' 2>/dev/null)
24
+
25
+ STATE_FILE="/tmp/cc-error-streak"
26
+ MAX_STREAK="${CC_ERROR_STREAK_MAX:-5}"
27
+
28
+ # Success resets the streak
29
+ if [ "$EXIT_CODE" = "0" ]; then
30
+ echo "0" > "$STATE_FILE"
31
+ exit 0
32
+ fi
33
+
34
+ # Increment error streak
35
+ CURRENT=$(cat "$STATE_FILE" 2>/dev/null || echo "0")
36
+ NEW_STREAK=$((CURRENT + 1))
37
+ echo "$NEW_STREAK" > "$STATE_FILE"
38
+
39
+ if [ "$NEW_STREAK" -ge "$MAX_STREAK" ]; then
40
+ echo "⚠ $NEW_STREAK consecutive errors detected. Claude may be stuck." >&2
41
+ echo "Last exit code: $EXIT_CODE" >&2
42
+ if [ -n "$STDERR" ]; then
43
+ echo "Last error: $(echo "$STDERR" | head -c 200)" >&2
44
+ fi
45
+ echo "Consider: try a different approach, check prerequisites, or ask for help." >&2
46
+ echo "To reset: rm /tmp/cc-error-streak" >&2
47
+ fi
48
+
49
+ exit 0
@@ -0,0 +1,47 @@
1
+ #!/bin/bash
2
+ # ================================================================
3
+ # tool-call-rate-limiter.sh — Prevent runaway tool calls
4
+ # ================================================================
5
+ # PURPOSE:
6
+ # Detects when Claude Code is making tool calls too rapidly,
7
+ # which usually indicates a stuck loop or runaway behavior
8
+ # that will burn through your quota.
9
+ #
10
+ # TRIGGER: PreToolUse
11
+ # MATCHER: (any — leave matcher empty to catch all tools)
12
+ #
13
+ # CONFIGURATION:
14
+ # CC_RATE_LIMIT_MAX=30 (max calls per window, default: 30)
15
+ # CC_RATE_LIMIT_WINDOW=60 (window in seconds, default: 60)
16
+ #
17
+ # See: https://github.com/anthropics/claude-code/issues/38335
18
+ # See: https://github.com/anthropics/claude-code/issues/37917
19
+ # ================================================================
20
+
21
+ RATE_FILE="${HOME}/.claude/rate-limiter.log"
22
+ MAX_CALLS="${CC_RATE_LIMIT_MAX:-30}"
23
+ WINDOW="${CC_RATE_LIMIT_WINDOW:-60}"
24
+
25
+ mkdir -p "$(dirname "$RATE_FILE")"
26
+
27
+ NOW=$(date +%s)
28
+ CUTOFF=$((NOW - WINDOW))
29
+
30
+ # Append current timestamp
31
+ echo "$NOW" >> "$RATE_FILE"
32
+
33
+ # Count calls within window
34
+ RECENT=$(awk -v cutoff="$CUTOFF" '$1 >= cutoff' "$RATE_FILE" 2>/dev/null | wc -l)
35
+
36
+ # Prune old entries (keep file small)
37
+ awk -v cutoff="$CUTOFF" '$1 >= cutoff' "$RATE_FILE" > "${RATE_FILE}.tmp" 2>/dev/null
38
+ mv "${RATE_FILE}.tmp" "$RATE_FILE" 2>/dev/null
39
+
40
+ if [ "$RECENT" -gt "$MAX_CALLS" ]; then
41
+ echo "BLOCKED: Rate limit exceeded — $RECENT tool calls in ${WINDOW}s (max: $MAX_CALLS)." >&2
42
+ echo "This usually means Claude is stuck in a loop. Check the task." >&2
43
+ echo "Set CC_RATE_LIMIT_MAX to adjust (current: $MAX_CALLS calls/${WINDOW}s)." >&2
44
+ exit 2
45
+ fi
46
+
47
+ exit 0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cc-safe-setup",
3
- "version": "29.6.4",
4
- "description": "One command to make Claude Code safe. 413 example hooks + 8 built-in. 52 CLI commands. 5613 tests. Works with Auto Mode.",
3
+ "version": "29.6.5",
4
+ "description": "One command to make Claude Code safe. 415 example hooks + 8 built-in. 52 CLI commands. 5627 tests. Works with Auto Mode.",
5
5
  "main": "index.mjs",
6
6
  "bin": {
7
7
  "cc-safe-setup": "index.mjs"