cc-safe-setup 29.6.24 → 29.6.25

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 445 examples |
120
+ | `--install-example <name>` | Install from 446 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,45 @@
1
+ #!/bin/bash
2
+ # api-overload-backoff.sh — Track API overload errors and enforce backoff
3
+ #
4
+ # Solves: 529 Overloaded errors causing session failures and wasted tokens.
5
+ # Multiple issues: #39743(24👍), #39763(18👍), #39745(14👍),
6
+ # #39767(11👍), #39747(8👍) — 75+ combined reactions.
7
+ # Users lose tokens on retries that hit the same overload.
8
+ #
9
+ # How it works: PostToolUse hook. Detects 529/overload errors in tool output.
10
+ # Tracks consecutive errors. After 3 consecutive 529s, warns
11
+ # to wait before retrying. After 5, suggests stopping the session.
12
+ #
13
+ # TRIGGER: PostToolUse MATCHER: ""
14
+ # ================================================================
15
+
16
+ INPUT=$(cat)
17
+ OUTPUT=$(echo "$INPUT" | jq -r '.tool_output // empty' 2>/dev/null)
18
+
19
+ [ -z "$OUTPUT" ] && exit 0
20
+
21
+ STATE="/tmp/cc-overload-count-$$"
22
+
23
+ # Detect 529/overload patterns in output
24
+ if echo "$OUTPUT" | grep -qiE '529|overloaded_error|overload|rate.limit.*exceeded'; then
25
+ # Increment counter
26
+ COUNT=1
27
+ [ -f "$STATE" ] && COUNT=$(( $(cat "$STATE") + 1 ))
28
+ echo "$COUNT" > "$STATE"
29
+
30
+ if [ "$COUNT" -ge 5 ]; then
31
+ echo "" >&2
32
+ echo "⚠ API OVERLOAD: $COUNT consecutive 529 errors detected." >&2
33
+ echo "The API is severely overloaded. Continuing will waste tokens." >&2
34
+ echo "Recommendation: Stop this session and retry in 10-15 minutes." >&2
35
+ elif [ "$COUNT" -ge 3 ]; then
36
+ echo "" >&2
37
+ echo "⚠ API OVERLOAD: $COUNT consecutive 529 errors." >&2
38
+ echo "Wait 30-60 seconds before the next action." >&2
39
+ fi
40
+ else
41
+ # Reset counter on successful response
42
+ rm -f "$STATE" 2>/dev/null
43
+ fi
44
+
45
+ exit 0
@@ -0,0 +1,53 @@
1
+ #!/bin/bash
2
+ # usage-cache-local.sh — Cache usage info locally to avoid API calls
3
+ #
4
+ # Solves: Asking "how much budget have I used?" costs tokens itself (#39465, 4👍).
5
+ # This hook tracks tool calls locally so you can check usage
6
+ # without making an API call.
7
+ #
8
+ # How it works: PostToolUse hook. Counts tool calls and estimates cost
9
+ # based on rough token averages. Writes to a local file
10
+ # that can be read with `cat /tmp/cc-usage-<hash>`.
11
+ #
12
+ # TRIGGER: PostToolUse MATCHER: ""
13
+ # ================================================================
14
+
15
+ INPUT=$(cat)
16
+ TOOL=$(echo "$INPUT" | jq -r '.tool_name // "unknown"' 2>/dev/null)
17
+
18
+ STATE="/tmp/cc-usage-$(echo "$PWD" | md5sum | cut -c1-8)"
19
+
20
+ # Read current state
21
+ CALLS=0
22
+ READS=0
23
+ WRITES=0
24
+ BASH_CALLS=0
25
+ if [ -f "$STATE" ]; then
26
+ eval "$(cat "$STATE")"
27
+ fi
28
+
29
+ # Increment
30
+ CALLS=$((CALLS + 1))
31
+ case "$TOOL" in
32
+ Read) READS=$((READS + 1)) ;;
33
+ Edit|Write) WRITES=$((WRITES + 1)) ;;
34
+ Bash) BASH_CALLS=$((BASH_CALLS + 1)) ;;
35
+ esac
36
+
37
+ # Save state
38
+ cat > "$STATE" << EOF
39
+ CALLS=$CALLS
40
+ READS=$READS
41
+ WRITES=$WRITES
42
+ BASH_CALLS=$BASH_CALLS
43
+ STARTED=${STARTED:-$(date +%s)}
44
+ EOF
45
+
46
+ # Show periodic summary (every 50 calls)
47
+ if [ $((CALLS % 50)) -eq 0 ]; then
48
+ DURATION=$(( ($(date +%s) - ${STARTED:-$(date +%s)}) / 60 ))
49
+ echo "📊 Session: $CALLS calls ($READS reads, $WRITES writes, $BASH_CALLS bash) in ${DURATION}min" >&2
50
+ echo " Check anytime: cat $STATE" >&2
51
+ fi
52
+
53
+ exit 0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cc-safe-setup",
3
- "version": "29.6.24",
4
- "description": "One command to make Claude Code safe. 446 example hooks + 8 built-in. 52 CLI commands. 6099 tests. Works with Auto Mode.",
3
+ "version": "29.6.25",
4
+ "description": "One command to make Claude Code safe. 448 example hooks + 8 built-in. 52 CLI commands. 6117 tests. Works with Auto Mode.",
5
5
  "main": "index.mjs",
6
6
  "bin": {
7
7
  "cc-safe-setup": "index.mjs"