cc-safe-setup 7.4.0 → 7.5.0

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
@@ -6,7 +6,7 @@
6
6
 
7
7
  **One command to make Claude Code safe for autonomous operation.** [日本語](docs/README.ja.md)
8
8
 
9
- 8 built-in + 51 examples = **59 hooks**. 26 CLI commands. 284 tests. [Web Tool](https://yurukusa.github.io/cc-safe-setup/) · [Cheat Sheet](https://yurukusa.github.io/cc-safe-setup/cheatsheet.html) · [Troubleshooting](TROUBLESHOOTING.md)
9
+ 8 built-in + 68 examples = **76 hooks**. 28 CLI commands. 394 tests. [Web Tool](https://yurukusa.github.io/cc-safe-setup/) · [Cheat Sheet](https://yurukusa.github.io/cc-safe-setup/cheatsheet.html) · [Troubleshooting](TROUBLESHOOTING.md)
10
10
 
11
11
  ```bash
12
12
  npx cc-safe-setup
@@ -87,7 +87,7 @@ Each hook exists because a real incident happened without it.
87
87
  | `--scan [--apply]` | Tech stack detection |
88
88
  | `--export / --import` | Team config sharing |
89
89
  | `--verify` | Test each hook |
90
- | `--install-example <name>` | Install from 51 examples |
90
+ | `--install-example <name>` | Install from 68 examples |
91
91
  | `--examples [filter]` | Browse examples by keyword |
92
92
  | `--full` | All-in-one setup |
93
93
  | `--status` | Check installed hooks |
@@ -0,0 +1,33 @@
1
+ #!/bin/bash
2
+ # ================================================================
3
+ # conflict-marker-guard.sh — Block commits with conflict markers
4
+ # ================================================================
5
+ # PURPOSE:
6
+ # Claude sometimes resolves merge conflicts incorrectly, leaving
7
+ # <<<<<<< / ======= / >>>>>>> markers in files. This hook checks
8
+ # staged files for conflict markers before allowing a commit.
9
+ #
10
+ # TRIGGER: PreToolUse MATCHER: "Bash"
11
+ # ================================================================
12
+
13
+ COMMAND=$(cat | jq -r '.tool_input.command // empty' 2>/dev/null)
14
+ [ -z "$COMMAND" ] && exit 0
15
+
16
+ # Only check on git commit
17
+ echo "$COMMAND" | grep -qE '^\s*git\s+commit' || exit 0
18
+
19
+ # Check staged files for conflict markers
20
+ CONFLICTS=$(git diff --cached --name-only 2>/dev/null | while read -r f; do
21
+ [ -f "$f" ] && grep -lE '^(<{7}|={7}|>{7})' "$f" 2>/dev/null
22
+ done)
23
+
24
+ if [ -n "$CONFLICTS" ]; then
25
+ COUNT=$(echo "$CONFLICTS" | wc -l)
26
+ echo "BLOCKED: $COUNT file(s) contain merge conflict markers:" >&2
27
+ echo "$CONFLICTS" | head -5 | sed 's/^/ /' >&2
28
+ echo "" >&2
29
+ echo "Resolve conflicts before committing." >&2
30
+ exit 2
31
+ fi
32
+
33
+ exit 0
@@ -0,0 +1,53 @@
1
+ #!/bin/bash
2
+ # ================================================================
3
+ # fact-check-gate.sh — Warn when docs reference unread source files
4
+ # ================================================================
5
+ # PURPOSE:
6
+ # Claude writes documentation that references source code without
7
+ # actually reading the files first. This leads to hallucinated
8
+ # function signatures, wrong parameter names, and false claims.
9
+ #
10
+ # This hook tracks which files were Read in the session, and warns
11
+ # when a doc edit mentions source files that weren't read.
12
+ #
13
+ # TRIGGER: PostToolUse MATCHER: "Edit|Write"
14
+ #
15
+ # Born from: https://github.com/anthropics/claude-code/issues/38057
16
+ # "Claude produces false claims in technical docs"
17
+ # ================================================================
18
+
19
+ INPUT=$(cat)
20
+ FILE=$(echo "$INPUT" | jq -r '.tool_input.file_path // empty' 2>/dev/null)
21
+ [ -z "$FILE" ] && exit 0
22
+
23
+ # Only check documentation files
24
+ case "$FILE" in
25
+ *.md|*.rst|*.txt|*/docs/*|*/doc/*|*README*|*CHANGELOG*|*CONTRIBUTING*)
26
+ ;;
27
+ *)
28
+ exit 0
29
+ ;;
30
+ esac
31
+
32
+ # Track reads in a session state file
33
+ STATE="/tmp/cc-fact-check-reads-$(echo "$PWD" | md5sum | cut -c1-8)"
34
+
35
+ # Get the content being written
36
+ CONTENT=$(echo "$INPUT" | jq -r '.tool_input.new_string // .tool_input.content // empty' 2>/dev/null)
37
+ [ -z "$CONTENT" ] && exit 0
38
+
39
+ # Extract referenced source files from the doc content
40
+ # Looks for: `filename.ext`, filename.ext, import from, require()
41
+ REFS=$(echo "$CONTENT" | grep -oE '`[a-zA-Z0-9_/-]+\.(js|ts|py|go|rs|java|rb|sh|mjs|cjs|jsx|tsx)`' | tr -d '`' | sort -u)
42
+ [ -z "$REFS" ] && exit 0
43
+
44
+ # Check if referenced files were read in this session
45
+ if [ ! -f "$STATE" ]; then
46
+ # No reads tracked yet — warn about all references
47
+ COUNT=$(echo "$REFS" | wc -l)
48
+ echo "WARNING: Doc references $COUNT source file(s) that may not have been read:" >&2
49
+ echo "$REFS" | head -5 | sed 's/^/ /' >&2
50
+ echo "Read the source files before documenting them to avoid hallucination." >&2
51
+ fi
52
+
53
+ exit 0
@@ -0,0 +1,54 @@
1
+ #!/bin/bash
2
+ # ================================================================
3
+ # token-budget-guard.sh — Estimate and limit session token cost
4
+ # ================================================================
5
+ # PURPOSE:
6
+ # Claude Code sessions can consume hundreds of dollars in tokens
7
+ # without the user realizing it. This hook estimates cumulative
8
+ # cost and warns/blocks when a budget threshold is exceeded.
9
+ #
10
+ # TRIGGER: PostToolUse MATCHER: ""
11
+ #
12
+ # CONFIG:
13
+ # CC_TOKEN_BUDGET=10 (warn at $10 estimated cost)
14
+ # CC_TOKEN_BLOCK=50 (block at $50 estimated cost)
15
+ #
16
+ # Born from: https://github.com/anthropics/claude-code/issues/38029
17
+ # "652k output tokens ($342) without user input"
18
+ # ================================================================
19
+
20
+ WARN_BUDGET="${CC_TOKEN_BUDGET:-10}"
21
+ BLOCK_BUDGET="${CC_TOKEN_BLOCK:-50}"
22
+ STATE="/tmp/cc-token-budget-$(echo "$PWD" | md5sum | cut -c1-8)"
23
+
24
+ # Estimate tokens from tool output size
25
+ INPUT=$(cat)
26
+ OUTPUT=$(echo "$INPUT" | jq -r '.tool_result // empty' 2>/dev/null)
27
+ OUTPUT_LEN=${#OUTPUT}
28
+
29
+ # Rough estimation: 1 token ≈ 4 chars, $15/M input + $75/M output for Opus
30
+ # This is approximate — actual costs depend on model and caching
31
+ TOKENS=$((OUTPUT_LEN / 4))
32
+
33
+ # Accumulate
34
+ TOTAL=0
35
+ [ -f "$STATE" ] && TOTAL=$(cat "$STATE" 2>/dev/null || echo 0)
36
+ TOTAL=$((TOTAL + TOKENS))
37
+ echo "$TOTAL" > "$STATE"
38
+
39
+ # Estimate cost (output tokens at $75/M for Opus)
40
+ # Using integer math: cost_cents = tokens * 75 / 10000
41
+ COST_CENTS=$((TOTAL * 75 / 10000))
42
+
43
+ if [ "$COST_CENTS" -ge "$((BLOCK_BUDGET * 100))" ]; then
44
+ echo "BLOCKED: Estimated session cost ~\$${COST_CENTS%??}.${COST_CENTS: -2} exceeds \$$BLOCK_BUDGET budget." >&2
45
+ echo "Reset: rm $STATE" >&2
46
+ exit 2
47
+ fi
48
+
49
+ if [ "$COST_CENTS" -ge "$((WARN_BUDGET * 100))" ]; then
50
+ echo "WARNING: Estimated session cost ~\$${COST_CENTS%??}.${COST_CENTS: -2} approaching \$$BLOCK_BUDGET limit." >&2
51
+ echo "Consider using /compact or starting a new session." >&2
52
+ fi
53
+
54
+ exit 0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cc-safe-setup",
3
- "version": "7.4.0",
3
+ "version": "7.5.0",
4
4
  "description": "One command to make Claude Code safe. 59 hooks (8 built-in + 51 examples). 26 CLI commands: dashboard, create, audit, lint, diff, migrate, compare, generate-ci. 284 tests.",
5
5
  "main": "index.mjs",
6
6
  "bin": {