cc-safe-setup 29.6.39 → 29.7.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.
Files changed (89) hide show
  1. package/.claude-plugin/marketplace.json +66 -0
  2. package/.claude-plugin/plugin.json +11 -0
  3. package/README.md +133 -12
  4. package/SETTINGS_REFERENCE.md +2 -0
  5. package/SKILL.md +47 -0
  6. package/TROUBLESHOOTING.md +26 -0
  7. package/examples/README.md +11 -1
  8. package/examples/activity-logger.sh +58 -0
  9. package/examples/allow-claude-settings.sh +3 -2
  10. package/examples/allow-git-hooks-dir.sh +3 -2
  11. package/examples/allow-protected-dirs.sh +3 -2
  12. package/examples/auto-approve-compound-git.sh +3 -0
  13. package/examples/auto-compact-context-monitor.sh +35 -0
  14. package/examples/auto-mode-safety-enforcer.sh +57 -0
  15. package/examples/background-task-guard.sh +57 -0
  16. package/examples/bash-heuristic-approver.sh +1 -1
  17. package/examples/broad-find-guard.sh +62 -0
  18. package/examples/cache-creation-spike-detector.sh +32 -0
  19. package/examples/case-insensitive-path-guard.sh +96 -0
  20. package/examples/cjk-punctuation-guard.sh +44 -0
  21. package/examples/clipboard-secret-guard.sh +29 -0
  22. package/examples/context-size-alert.sh +38 -0
  23. package/examples/context-usage-drift-alert.sh +33 -0
  24. package/examples/dangerous-pip-flag-guard.sh +51 -0
  25. package/examples/decision-warn.sh +59 -0
  26. package/examples/deny-bypass-detector.sh +143 -0
  27. package/examples/direnv-auto-reload.sh +9 -2
  28. package/examples/dotenv-commit-guard.sh +11 -5
  29. package/examples/dotenv-read-guard.sh +48 -0
  30. package/examples/dotfile-protection-guard.sh +60 -0
  31. package/examples/effort-tracking-logger.sh +30 -0
  32. package/examples/financial-operation-guard.sh +47 -0
  33. package/examples/full-rewrite-detector.sh +63 -0
  34. package/examples/home-critical-bash-guard.sh +56 -0
  35. package/examples/idle-session-cost-alert.sh +36 -0
  36. package/examples/model-version-alert.sh +18 -0
  37. package/examples/model-version-change-alert.sh +31 -0
  38. package/examples/move-delete-sequence-guard.sh +92 -0
  39. package/examples/pii-upload-guard.sh +72 -0
  40. package/examples/pr-duplicate-guard.sh +14 -0
  41. package/examples/production-port-kill-guard.sh +60 -0
  42. package/examples/proof-log-session.sh +62 -0
  43. package/examples/quota-reset-cycle-monitor.sh +30 -0
  44. package/examples/repo-visibility-guard.sh +33 -0
  45. package/examples/sandbox-relative-path-audit.sh +51 -0
  46. package/examples/session-agent-cost-limiter.sh +43 -0
  47. package/examples/session-cost-alert.sh +62 -0
  48. package/examples/session-memory-watchdog.sh +9 -0
  49. package/examples/settings-integrity-monitor.sh +55 -0
  50. package/examples/settings-json-model-guard.sh +89 -0
  51. package/examples/shell-config-truncation-guard.sh +97 -0
  52. package/examples/shell-wrapper-guard.sh +4 -4
  53. package/examples/subagent-spawn-rate-monitor.sh +34 -0
  54. package/examples/subcommand-chain-guard.sh +44 -0
  55. package/examples/system-dir-protection-guard.sh +100 -0
  56. package/examples/thinking-display-enforcer.sh +25 -0
  57. package/examples/tool-retry-budget-guard.sh +59 -0
  58. package/examples/worktree-branch-pollution-detector.sh +35 -0
  59. package/examples/worktree-create-log.sh +6 -0
  60. package/examples/worktree-hook-linker.sh +72 -0
  61. package/examples/worktree-remove-uncommitted-guard.sh +20 -0
  62. package/hooks/hooks.json +60 -0
  63. package/index.mjs +108 -6
  64. package/memory/market-anthropic-japan-strategy-2026-04-13.md +4 -0
  65. package/package.json +2 -2
  66. package/plugins/credential-guard/.claude-plugin/plugin.json +58 -0
  67. package/plugins/git-protection/.claude-plugin/plugin.json +58 -0
  68. package/plugins/safety-essentials/.claude-plugin/plugin.json +58 -0
  69. package/plugins/token-guard/.claude-plugin/plugin.json +51 -0
  70. package/skills/safety-setup/SKILL.md +47 -0
  71. package/tests/dotenv-read-guard.test.sh +65 -0
  72. package/tests/test-auto-mode-safety-enforcer.sh +55 -0
  73. package/tests/test-case-insensitive-path-guard.sh +78 -0
  74. package/tests/test-context-usage-drift-alert.sh +52 -0
  75. package/tests/test-dangerous-pip-flag-guard.sh +56 -0
  76. package/tests/test-dotfile-protection-guard.sh +68 -0
  77. package/tests/test-effort-tracking-logger.sh +55 -0
  78. package/tests/test-financial-operation-guard.sh +59 -0
  79. package/tests/test-home-critical-bash-guard.sh +59 -0
  80. package/tests/test-model-version-change-alert.sh +55 -0
  81. package/tests/test-move-delete-sequence-guard.sh +63 -0
  82. package/tests/test-pr-duplicate-guard.sh +29 -0
  83. package/tests/test-quota-reset-cycle-monitor.sh +52 -0
  84. package/tests/test-shell-config-truncation-guard.sh +104 -0
  85. package/tests/test-subagent-spawn-rate-monitor.sh +43 -0
  86. package/tests/test-system-dir-protection-guard.sh +81 -0
  87. package/tests/test-tool-retry-budget-guard.sh +75 -0
  88. package/tests/test-worktree-branch-pollution-detector.sh +50 -0
  89. package/tests/test-worktree-lifecycle-hooks.sh +29 -0
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "cc-safe-setup",
3
+ "owner": {
4
+ "name": "yurukusa",
5
+ "email": "yurukusa@users.noreply.github.com"
6
+ },
7
+ "metadata": {
8
+ "description": "Safety hooks for Claude Code — 688 battle-tested hooks from 800+ hours of autonomous operation. Prevents rm -rf, force-push, credential leaks, unauthorized fund transfers, deny-rules bypass, and more.",
9
+ "version": "1.0.0",
10
+ "pluginRoot": "./plugins"
11
+ },
12
+ "plugins": [
13
+ {
14
+ "name": "safety-essentials",
15
+ "source": "./plugins/safety-essentials",
16
+ "description": "5 essential safety hooks: block rm -rf, force-push, hard-reset, env overwrites, and package publish. The minimum viable safety net.",
17
+ "version": "1.0.0",
18
+ "author": { "name": "yurukusa" },
19
+ "homepage": "https://yurukusa.github.io/cc-safe-setup/",
20
+ "repository": "https://github.com/yurukusa/cc-safe-setup",
21
+ "license": "MIT",
22
+ "keywords": ["safety", "hooks", "rm-rf", "force-push", "env", "essential"],
23
+ "category": "safety",
24
+ "tags": ["beginner-friendly", "must-have", "pretooluse"]
25
+ },
26
+ {
27
+ "name": "git-protection",
28
+ "source": "./plugins/git-protection",
29
+ "description": "Git safety hooks: block force-push, protect main/master, prevent hard-reset, guard rebase, and auto-backup before destructive operations.",
30
+ "version": "1.0.0",
31
+ "author": { "name": "yurukusa" },
32
+ "homepage": "https://yurukusa.github.io/cc-safe-setup/",
33
+ "repository": "https://github.com/yurukusa/cc-safe-setup",
34
+ "license": "MIT",
35
+ "keywords": ["git", "force-push", "main-branch", "reset", "rebase", "backup"],
36
+ "category": "safety",
37
+ "tags": ["git", "version-control", "pretooluse"]
38
+ },
39
+ {
40
+ "name": "credential-guard",
41
+ "source": "./plugins/credential-guard",
42
+ "description": "Protect secrets and credentials: block writes to .env files, detect API keys in commands, prevent hardcoded tokens, guard service account files.",
43
+ "version": "1.0.0",
44
+ "author": { "name": "yurukusa" },
45
+ "homepage": "https://yurukusa.github.io/cc-safe-setup/",
46
+ "repository": "https://github.com/yurukusa/cc-safe-setup",
47
+ "license": "MIT",
48
+ "keywords": ["credentials", "secrets", "api-keys", "env", "tokens", "security"],
49
+ "category": "security",
50
+ "tags": ["credentials", "secrets", "pretooluse"]
51
+ },
52
+ {
53
+ "name": "token-guard",
54
+ "source": "./plugins/token-guard",
55
+ "description": "Token consumption guards: large-read warning (100KB+), read budget limit, subagent cap, and token budget tracking. Reduce waste by 20-40%.",
56
+ "version": "1.0.0",
57
+ "author": { "name": "yurukusa" },
58
+ "homepage": "https://yurukusa.github.io/cc-safe-setup/token-book.html",
59
+ "repository": "https://github.com/yurukusa/cc-safe-setup",
60
+ "license": "MIT",
61
+ "keywords": ["tokens", "cost", "budget", "optimization", "large-read", "subagent"],
62
+ "category": "optimization",
63
+ "tags": ["token-saving", "cost-reduction", "pretooluse", "posttooluse"]
64
+ }
65
+ ]
66
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "cc-safe-setup",
3
+ "description": "665 safety hooks for Claude Code — prevent file deletion, credential leaks, git disasters, and token waste during autonomous AI coding sessions",
4
+ "version": "30.0.0",
5
+ "author": {
6
+ "name": "yurukusa"
7
+ },
8
+ "homepage": "https://yurukusa.github.io/cc-safe-setup/",
9
+ "repository": "https://github.com/yurukusa/cc-safe-setup",
10
+ "license": "MIT"
11
+ }
package/README.md CHANGED
@@ -4,23 +4,29 @@
4
4
  [![npm downloads](https://img.shields.io/npm/dw/cc-safe-setup)](https://www.npmjs.com/package/cc-safe-setup)
5
5
  [![tests](https://github.com/yurukusa/cc-safe-setup/actions/workflows/test.yml/badge.svg)](https://github.com/yurukusa/cc-safe-setup/actions/workflows/test.yml)
6
6
 
7
- **One command to make Claude Code safe for autonomous operation.** 650 example hooks · 14,078 tests · 1,000+ installs/day · [日本語](docs/README.ja.md)
7
+ > 🚀 **Launching on [Product Hunt](https://www.producthunt.com/products/cc-safe-setup) April 21!** Follow us and upvote to support open source safety for AI coding agents.
8
+
9
+ **One command to make Claude Code safe for autonomous operation.** 700 example hooks · 9,200+ tests · 30K+ total installs · [日本語](docs/README.ja.md)
8
10
 
9
11
  ```bash
10
12
  npx cc-safe-setup
11
13
  ```
12
14
 
13
- Installs 8 safety hooks in ~10 seconds. Blocks `rm -rf /`, prevents pushes to main, catches secret leaks, validates syntax after every edit. Zero dependencies.
15
+ Installs 8 safety hooks in ~10 seconds. Blocks `rm -rf /`, prevents pushes to main, catches secret leaks, validates syntax after every edit. Zero npm dependencies. Hooks use [`jq`](https://jqlang.github.io/jq/) at runtime (`brew install jq` / `apt install jq`).
14
16
 
15
17
  > **What's a hook?** A checkpoint that runs before Claude executes a command. Like airport security — it inspects what's about to happen and blocks anything dangerous before it reaches the gate.
16
18
 
17
- [**Getting Started**](https://yurukusa.github.io/cc-safe-setup/getting-started.html) · [**All Tools**](https://yurukusa.github.io/cc-safe-setup/hub.html) · [**Recipes**](https://yurukusa.github.io/cc-safe-setup/recipes.html) · [Validate your settings.json](https://yurukusa.github.io/cc-safe-setup/validator.html) · [**Check your score**](https://yurukusa.github.io/cc-health-check/) (`npx cc-health-check`)
19
+ [**Getting Started**](https://yurukusa.github.io/cc-safe-setup/getting-started.html) · [**Hook Selector**](https://yurukusa.github.io/cc-safe-setup/hook-selector.html) · [**Token Checkup**](https://yurukusa.github.io/cc-safe-setup/token-checkup.html) · [**Cache Health**](https://yurukusa.github.io/cc-safe-setup/cache-health.html) · [**Version Check**](https://yurukusa.github.io/cc-safe-setup/version-check.html) · [**CLAUDE.md Analyzer**](https://yurukusa.github.io/cc-safe-setup/claudemd-analyzer.html) · [**All Tools**](https://yurukusa.github.io/cc-safe-setup/hub.html) · [**Recipes**](https://yurukusa.github.io/cc-safe-setup/recipes.html) · [Validate your settings.json](https://yurukusa.github.io/cc-safe-setup/validator.html) · [**Check your score**](https://yurukusa.github.io/cc-health-check/) (`npx cc-health-check`) · [**Safety Audit**](https://yurukusa.github.io/cc-safe-setup/safety-audit.html)
18
20
 
19
21
  ```
20
22
  cc-safe-setup
21
23
  Make Claude Code safe for autonomous operation
22
24
 
23
25
  Prevents real incidents (from GitHub Issues):
26
+ ✗ rm -rf permanently destroyed ~50 GB / 1,500 files (#49129) ← April 2026
27
+ ✗ Auto mode approved ~/.ssh deletion — all SSH keys gone (#49554)
28
+ ✗ ~/.git-credentials PATs deleted without confirmation (#49539)
29
+ ✗ rm -rf deleted 3,467 files (~7 GB) without confirmation (#46058)
24
30
  ✗ rm -rf deleted entire user directory via NTFS junction (#36339)
25
31
  ✗ Remove-Item -Recurse -Force destroyed unpushed source (#37331)
26
32
  ✗ Entire Mac filesystem deleted during cleanup (#36233)
@@ -29,6 +35,10 @@ Installs 8 safety hooks in ~10 seconds. Blocks `rm -rf /`, prevents pushes to ma
29
35
  ✗ API keys committed to public repos via git add .
30
36
  ✗ Syntax errors cascading through 30+ files
31
37
  ✗ Sessions losing all context with no warning
38
+ ✗ CLAUDE.md rules silently ignored after context compaction
39
+ ✗ Claude ran destructive DDL on production database (#46684)
40
+ ✗ AI executed delete/kill operations on production environment (#46650)
41
+ ✗ Subagents ignoring all CLAUDE.md rules since v2.1.84 (#40459)
32
42
 
33
43
  Hooks to install:
34
44
 
@@ -47,17 +57,35 @@ Installs 8 safety hooks in ~10 seconds. Blocks `rm -rf /`, prevents pushes to ma
47
57
 
48
58
  ## Why This Exists
49
59
 
50
- A Claude Code user [lost their entire C:\Users directory](https://github.com/anthropics/claude-code/issues/36339) when `rm -rf` followed NTFS junctions. Another [lost all source code](https://github.com/anthropics/claude-code/issues/37331) when Claude ran `Remove-Item -Recurse -Force *` on a repo. Others had untested code pushed to main at 3am. API keys got committed via `git add .`. Syntax errors cascaded through 30+ files before anyone noticed.
60
+ A user [lost 3,467 files (~7 GB)](https://github.com/anthropics/claude-code/issues/46058) when Claude ran `rm -rf` on their data directory without confirmation. Another [lost their entire C:\Users directory](https://github.com/anthropics/claude-code/issues/36339) when `rm -rf` followed NTFS junctions. Another [lost all source code](https://github.com/anthropics/claude-code/issues/37331) when Claude ran `Remove-Item -Recurse -Force *` on a repo. One user's Claude [ran destructive DDL on a production database](https://github.com/anthropics/claude-code/issues/46684) when asked only to investigate. Another had Claude [execute delete and kill operations on production systems](https://github.com/anthropics/claude-code/issues/46650). Others had untested code pushed to main at 3am. API keys got committed via `git add .`. Syntax errors cascaded through 30+ files before anyone noticed. And [CLAUDE.md rules get silently dropped](https://github.com/anthropics/claude-code/issues/6354) after context compaction — your instructions vanish mid-session.
61
+
62
+ One user [analyzed 6,852 sessions](https://github.com/anthropics/claude-code/issues/42796) and found the Read:Edit ratio dropped from 6.6 to 2.0 — Claude editing files it never read jumped from 6% to 34%. That issue has over 2,100 reactions. The `read-before-edit` example hook catches this pattern before damage happens.
63
+
64
+ In April 2026, [$1,446 was transferred without authorization](https://github.com/anthropics/claude-code/issues/46828) when Claude moved funds between exchange accounts. A user [lost $367 and got their account suspended](https://github.com/anthropics/claude-code/issues/47046) from a Claude-generated script. [Physical coordinates were uploaded to a public website](https://github.com/anthropics/claude-code/issues/46910) despite 17 sessions of "no PII" in CLAUDE.md. And [deny rules can be bypassed with 50+ subcommands](https://adversa.ai/blog/claude-code-security-bypass-deny-rules-disabled/).
51
65
 
52
- Claude Code ships with no safety hooks by default. This tool fixes that.
66
+ Claude Code ships with no safety hooks by default. This tool fixes that. ([Standalone guard script](https://gist.github.com/yurukusa/87f51b97bb655357dd148b66109d0c14) for quick setup | [Database protection hooks](https://gist.github.com/yurukusa/ad27e541769992e9e0cd15c1b487a1d2) | [Credential protection hooks](https://gist.github.com/yurukusa/7292ead735df0aa673f0485eba5587f3) | [Fabrication detection hook](https://gist.github.com/yurukusa/03f4bbbab61f7ddf31049cc28a01d0d9) | [Security vulnerability hooks](https://gist.github.com/yurukusa/81f79ae6d760b27c17f2cd642ea846d7))
53
67
 
54
68
  **Works with Auto Mode.** Claude Code's [Auto Mode sandboxing](https://www.anthropic.com/engineering/claude-code-sandboxing) provides container-level isolation. cc-safe-setup adds process-level hooks as defense-in-depth — catching destructive commands even outside sandboxed environments.
55
69
 
70
+ **Works with subagents.** Since v2.1.84, subagents and teammates [don't receive CLAUDE.md](https://github.com/anthropics/claude-code/issues/40459) — your project rules are silently skipped. Hooks operate at the process level, but [subagent tool calls may bypass PreToolUse hooks](https://github.com/anthropics/claude-code/issues/21460) in some configurations. As defense-in-depth, cc-safe-setup installs hooks at the user level (`~/.claude/settings.json`). The `subagent-claudemd-inject` example hook re-injects critical rules into subagent prompts.
71
+
72
+ ### 🚨 Opus 4.7 Crisis (April 2026)
73
+
74
+ Opus 4.7 broke auto mode's safety classifier — it was [hardcoded to Opus 4.6](https://github.com/anthropics/claude-code/issues/49618). **If you use auto mode with Opus 4.7, dangerous commands run without the built-in safety check.** In 3 days: [50 GB permanently deleted](https://github.com/anthropics/claude-code/issues/49129), [~/.ssh wiped](https://github.com/anthropics/claude-code/issues/49554), [git credentials destroyed](https://github.com/anthropics/claude-code/issues/49539), [shell configs truncated to 0 bytes](https://github.com/anthropics/claude-code/issues/49615). Users report [4x token consumption](https://github.com/anthropics/claude-code/issues/49541) from silent model switches.
75
+
76
+ **One command to fix it:**
77
+
78
+ ```bash
79
+ npx cc-safe-setup --opus47
80
+ ```
81
+
82
+ Installs 4 hooks targeting known Opus 4.7 regressions. [Full details →](https://yurukusa.github.io/cc-safe-setup/opus-47-survival-guide.html) · [Emergency Defense Kit (Gist)](https://gist.github.com/yurukusa/6747ea655cc5c374a1ec9ed4fba027e4) · [Safety Scanner](https://yurukusa.github.io/cc-safe-setup/opus47-scanner.html)
83
+
56
84
  ## What Gets Installed
57
85
 
58
86
  | Hook | Prevents | Related Issues |
59
87
  |------|----------|----------------|
60
- | **Destructive Guard** | `rm -rf /`, `git reset --hard`, `git clean -fd`, `git checkout --force`, `sudo` + destructive, PowerShell `Remove-Item -Recurse -Force`, `rd /s /q`, NFS mount detection | [#36339](https://github.com/anthropics/claude-code/issues/36339) [#36640](https://github.com/anthropics/claude-code/issues/36640) [#37331](https://github.com/anthropics/claude-code/issues/37331) |
88
+ | **Destructive Guard** | `rm -rf /`, `git reset --hard`, `git clean -fd`, `git checkout --force`, `sudo` + destructive, PowerShell `Remove-Item -Recurse -Force`, `rd /s /q`, NFS mount detection | [#46058](https://github.com/anthropics/claude-code/issues/46058) [#36339](https://github.com/anthropics/claude-code/issues/36339) [#36640](https://github.com/anthropics/claude-code/issues/36640) [#37331](https://github.com/anthropics/claude-code/issues/37331) |
61
89
  | **Branch Guard** | Pushes to main/master + force-push (`--force`) on all branches | |
62
90
  | **Secret Guard** | `git add .env`, credential files, `git add .` with .env present | [#6527](https://github.com/anthropics/claude-code/issues/6527) |
63
91
  | **Syntax Check** | Python, Shell, JSON, YAML, JS errors after edits | |
@@ -66,10 +94,25 @@ Claude Code ships with no safety hooks by default. This tool fixes that.
66
94
  | **cd+git Auto-Approver** | Permission prompt spam for `cd /path && git log` | [#32985](https://github.com/anthropics/claude-code/issues/32985) [#16561](https://github.com/anthropics/claude-code/issues/16561) |
67
95
  | **API Error Alert** | Silent session death from rate limits or API errors — desktop notification + log | |
68
96
 
69
- > 📘 Tokens disappearing too fast? [The practical guide](https://zenn.dev/yurukusa/books/6076c23b1cb18b) covers 10 token consumption patterns (cache corruption, excessive reads, compact cycles) and how to detect them — from 700+ hours of autonomous operation. Chapter 3 free.
70
-
71
97
  Each hook exists because a real incident happened without it.
72
98
 
99
+ ### Free diagnostic tools
100
+
101
+ | Tool | What it does |
102
+ |------|-------------|
103
+ | **[Token Checkup](https://yurukusa.github.io/cc-safe-setup/token-checkup.html)** | 5 questions → find where your tokens are going (30 seconds) |
104
+ | **[Security Checkup](https://yurukusa.github.io/cc-safe-setup/security-checkup.html)** | 6 questions based on real incidents ($1,800+ in losses) |
105
+ | **[Version Check](https://yurukusa.github.io/cc-safe-setup/version-check.html)** | Is your CC version affected by cache inflation? |
106
+
107
+ ### Go deeper
108
+
109
+ | Resource | What you get | Price |
110
+ |----------|-------------|-------|
111
+ | **[Token Book](https://yurukusa.github.io/cc-safe-setup/token-book.html)** | Cut token consumption in half. CLAUDE.md templates, hook configs, context management, 32 failure patterns with fixes. 44,000+ words from 800+ hours of real operation data. | ¥2,500 (~$17). Ch.1 free |
112
+ | **[Safety Guide](https://zenn.dev/yurukusa/books/6076c23b1cb18b)** | End-to-end Claude Code safety setup. From first install to overnight autonomous runs. | ¥800 (~$5). Ch.3 free |
113
+
114
+ **Why pay?** A Max plan costs $200/month. One token waste incident burns 50–80% of your weekly quota in hours ([#46727](https://github.com/anthropics/claude-code/issues/46727)). One `rm -rf` incident costs days of recovery. The Token Book costs less than 2 hours of Max subscription time — and the CLAUDE.md templates alone can reduce consumption by 40%.
115
+
73
116
  ### v2.1.85: `if` Field Support
74
117
 
75
118
  Hooks now support an `if` field for conditional execution. The hook process only spawns when the command matches the pattern — `ls` won't trigger a git-only hook.
@@ -120,6 +163,7 @@ Guards against issues that corrupt sessions or waste tokens silently.
120
163
  | `mcp-warmup-wait` | Waits for MCP servers to initialize on session start (fixes first-turn tool errors) | [#41778](https://github.com/anthropics/claude-code/issues/41778) |
121
164
  | `pre-compact-transcript-backup` | Full JSONL backup before compaction (protects against rate-limit data loss) | [#40352](https://github.com/anthropics/claude-code/issues/40352) |
122
165
  | `conversation-history-guard` | Blocks access to session JSONL files (prevents 20x cache poisoning) | [#40524](https://github.com/anthropics/claude-code/issues/40524) |
166
+ | `read-before-edit` | Warns when Edit targets a file not recently Read (Read:Edit ratio dropped 70% — [#42796](https://github.com/anthropics/claude-code/issues/42796)) | [#42796](https://github.com/anthropics/claude-code/issues/42796) |
123
167
  | `replace-all-guard` | Warns/blocks Edit `replace_all:true` (prevents bulk data corruption) | [#41681](https://github.com/anthropics/claude-code/issues/41681) |
124
168
  | `ripgrep-permission-fix` | Auto-fixes vendored ripgrep +x permission on start (fixes broken commands/skills) | [#41933](https://github.com/anthropics/claude-code/issues/41933) |
125
169
 
@@ -146,7 +190,7 @@ Guards against issues that corrupt sessions or waste tokens silently.
146
190
  | `--scan [--apply]` | Tech stack detection |
147
191
  | `--export / --import` | Team config sharing |
148
192
  | `--verify` | Test each hook |
149
- | `--install-example <name>` | Install from 650 examples |
193
+ | `--install-example <name>` | Install from 700 examples |
150
194
  | `--examples [filter]` | Browse examples by keyword |
151
195
  | `--full` | All-in-one setup |
152
196
  | `--status` | Check installed hooks |
@@ -204,6 +248,23 @@ Guards against issues that corrupt sessions or waste tokens silently.
204
248
  | Maximum protection mode | `npx cc-safe-setup --safe-mode` |
205
249
  | Migrate from Cursor/Windsurf | [Migration Guide](https://yurukusa.github.io/cc-safe-setup/migration-guide.html) |
206
250
 
251
+ ## Plugin Marketplace
252
+
253
+ Install safety hooks as Claude Code plugins — no npm required:
254
+
255
+ ```bash
256
+ /plugin marketplace add yurukusa/cc-safe-setup
257
+ /plugin install safety-essentials@cc-safe-setup
258
+ ```
259
+
260
+ | Plugin | What it blocks |
261
+ |---|---|
262
+ | `safety-essentials` | rm -rf, force-push, hard-reset, .env overwrite, npm publish |
263
+ | `git-protection` | Force-push, main/master push, git clean, branch -D |
264
+ | `credential-guard` | .env write/edit, API keys in commands, service account files |
265
+
266
+ Also listed on [claudemarketplaces.com](https://claudemarketplaces.com).
267
+
207
268
  ## Common Pain Points (from GitHub Issues)
208
269
 
209
270
  | Problem | Issue | Fix |
@@ -245,7 +306,10 @@ Safe to run multiple times. Existing settings are preserved. A backup is created
245
306
 
246
307
  **Note:** Hooks are skipped when Claude Code runs with `--bare` or `--dangerously-skip-permissions`. These modes bypass all safety hooks by design.
247
308
 
248
- **Known limitation:** In headless mode (`-p` / `--print`), hook exit code 2 may not block tool execution ([#36071](https://github.com/anthropics/claude-code/issues/36071)). For CI pipelines, use interactive mode with hooks rather than `-p` mode.
309
+ **Known limitations:**
310
+
311
+ - In headless mode (`-p` / `--print`), hook exit code 2 may not block tool execution ([#36071](https://github.com/anthropics/claude-code/issues/36071)). For CI pipelines, use interactive mode with hooks rather than `-p` mode.
312
+ - `FileChanged` notifications inject file contents into model context **before** hooks can intervene. If a sensitive file (`.env`, `credentials.json`) is modified externally during a session, its contents may appear in the conversation transcript regardless of hooks ([#44909](https://github.com/anthropics/claude-code/issues/44909)). Mitigation: use `dotenv-watch` to get alerted, and avoid editing sensitive files while Claude Code is running.
249
313
 
250
314
  ## Before / After
251
315
 
@@ -285,6 +349,8 @@ cc-safe-setup gives you 8 essential hooks. Want to know what else your setup nee
285
349
 
286
350
  Run `npx cc-health-check` (free, 20 checks) to see your current score. If it's below 80, the **[Claude Code Ops Kit](https://yurukusa.github.io/cc-ops-kit-landing/?utm_source=github&utm_medium=readme&utm_campaign=safe-setup)** fills the gaps — 6 hooks + 5 templates + 9 scripts + install.sh. Pay What You Want ($0+).
287
351
 
352
+ **Starter Kit:** Want hooks + settings + templates in one download? The **[Claude Code Safety Kit](https://yurukusa.itch.io/claude-code-safety-kit)** bundles 5 safety hooks, a pre-configured settings.json, CLAUDE.md templates, and 800-hour operation tips. Name your price ($0+).
353
+
288
354
  Or browse the free hooks: [claude-code-hooks](https://github.com/yurukusa/claude-code-hooks)
289
355
 
290
356
  ## Examples
@@ -352,7 +418,7 @@ Or browse all available examples in [`examples/`](examples/):
352
418
  - **edit-guard.sh** — Block Edit/Write to protected files (defense-in-depth for [#37210](https://github.com/anthropics/claude-code/issues/37210))
353
419
  - **auto-approve-build.sh** — Auto-approve npm/yarn/cargo/go/python build, test, and lint commands
354
420
  - **auto-approve-docker.sh** — Auto-approve docker build, compose, ps, logs, and other safe commands
355
- - **block-database-wipe.sh** — Block destructive database commands: Laravel `migrate:fresh`, Django `flush`, Rails `db:drop`, raw `DROP DATABASE` ([#37405](https://github.com/anthropics/claude-code/issues/37405) [#37439](https://github.com/anthropics/claude-code/issues/37439))
421
+ - **block-database-wipe.sh** — Block destructive database commands: Laravel `migrate:fresh`, Django `flush`, Rails `db:drop`, raw `DROP DATABASE` ([#46684](https://github.com/anthropics/claude-code/issues/46684) [#46650](https://github.com/anthropics/claude-code/issues/46650) [#37405](https://github.com/anthropics/claude-code/issues/37405) [#37439](https://github.com/anthropics/claude-code/issues/37439))
356
422
  - **auto-approve-python.sh** — Auto-approve pytest, mypy, ruff, black, isort, flake8, pylint commands
357
423
  - **auto-snapshot.sh** — Auto-save file snapshots before edits for rollback protection ([#37386](https://github.com/anthropics/claude-code/issues/37386) [#37457](https://github.com/anthropics/claude-code/issues/37457))
358
424
  - **allowlist.sh** — Block everything not explicitly approved — inverse permission model ([#37471](https://github.com/anthropics/claude-code/issues/37471))
@@ -429,13 +495,18 @@ See [Issue #1](https://github.com/yurukusa/cc-safe-setup/issues/1) for details.
429
495
 
430
496
  ## Learn More
431
497
 
432
- - **[Practical Guide (Zenn Book)](https://zenn.dev/yurukusa/books/6076c23b1cb18b)** — Token consumption diagnosis, file loss prevention, autonomous operation safety. 14 chapters from 700+ hours of real incidents. [Chapter 3 free](https://zenn.dev/yurukusa/books/6076c23b1cb18b/viewer/3-code-quality)
498
+ - **[Opus 4.7 Survival Guide](https://yurukusa.github.io/cc-safe-setup/opus-47-survival-guide.html)** — 50 known issues (67+ GitHub Issues + CVEs) with fixes: data loss, recursive spawn DoS, billing mismatch, subagent OOM, cache_read anomaly, allowedTools bypass, 1.7x token inflation, classifier failure, thinking summary bugs, 30-min stalls, and more. [`npx cc-safe-setup --opus47`](#-opus-47-crisis-april-2026)
499
+ - **[Token Book (¥2,500)](https://zenn.dev/yurukusa/books/token-savings-guide)** — Cut token consumption in half. CLAUDE.md optimization, hook-based guards, context management, workflow design. 44,000 words with copy-paste templates. Intro + Ch.1 free. [Details](https://yurukusa.github.io/cc-safe-setup/token-book.html)
500
+ - **[Safety Guide (¥800)](https://zenn.dev/yurukusa/books/6076c23b1cb18b)** — Token consumption diagnosis, file loss prevention, autonomous operation safety. From 800+ hours of real incidents. [Chapter 3 free](https://zenn.dev/yurukusa/books/6076c23b1cb18b/viewer/3-code-quality)
501
+ - **[800 Hours Operation Record (¥800)](https://zenn.dev/yurukusa/books/3c3c3baee85f0a19)** — Non-engineer running Claude Code autonomously for 800 hours. Failures, recovery, revenue reality. [Chapter 2 free](https://zenn.dev/yurukusa/books/3c3c3baee85f0a19/viewer/2-first-failures)
502
+ - **Wiki Guides**: [Token FAQ](https://github.com/yurukusa/cc-safe-setup/wiki/Claude-Code-Token-FAQ) · [CLAUDE.md Best Practices](https://github.com/yurukusa/cc-safe-setup/wiki/CLAUDE-md-Best-Practices) · [Token Optimization](https://github.com/yurukusa/cc-safe-setup/wiki/Token-Optimization-Guide)
433
503
  - [Cookbook](COOKBOOK.md) — 26 practical recipes (block, approve, protect, monitor, diagnose)
434
504
  - [Official Hooks Reference](https://code.claude.com/docs/en/hooks) — Claude Code hooks documentation
435
505
  - [Hooks Cookbook](https://github.com/yurukusa/claude-code-hooks/blob/main/COOKBOOK.md) — 25 recipes from real GitHub Issues ([interactive version](https://yurukusa.github.io/claude-code-hooks/))
436
506
  - [Skills Guide deep-dive (Qiita, 19K+ views)](https://qiita.com/yurukusa/items/f69920b4a02cf7e2988c) — Anthropic's official Skills PDF analyzed with 40% token reduction
437
507
  - [Japanese guide (Qiita)](https://qiita.com/yurukusa/items/a9714b33f5d974e8f1e8) — この記事の日本語解説
438
508
  - [v2.1.85 `if` field guide (Qiita)](https://qiita.com/yurukusa/items/7079866e9dc239fcdd57) — Reduce hook overhead with conditional execution
509
+ - [Deny rules bypass vulnerability (Qiita)](https://qiita.com/yurukusa/items/f9c48bb44569bbf4492e) — 50+ subcommands disable all deny rules; hook-based defense
439
510
  - [Hook Test Runner](https://github.com/yurukusa/cc-hook-test) — `npx cc-hook-test <hook.sh>` to auto-test any hook
440
511
  - [Hook Registry](https://github.com/yurukusa/cc-hook-registry) — `npx cc-hook-registry search database` ([browse online](https://yurukusa.github.io/cc-hook-registry/))
441
512
  - [Hooks Cheat Sheet](https://yurukusa.github.io/cc-safe-setup/cheatsheet.html) — printable A4 quick reference
@@ -445,6 +516,46 @@ See [Issue #1](https://github.com/yurukusa/cc-safe-setup/issues/1) for details.
445
516
  - [How to prevent force-push to main](https://yurukusa.github.io/cc-safe-setup/prevent-force-push.html) — branch protection via hooks
446
517
  - [How to prevent secret leaks](https://yurukusa.github.io/cc-safe-setup/prevent-secret-leaks.html) — stop git add . from committing .env
447
518
 
519
+ ### Free Gists
520
+
521
+ - [settings.json Complete Template](https://gist.github.com/yurukusa/8ec367cf65042bf9fbd83c35931e7ed1) — copy-paste ready safety configuration
522
+ - [First 3 Safety Steps](https://gist.github.com/yurukusa/72513272be9a4ee29b058e2b08453e1a) — 5-minute safety setup from scratch
523
+ - [CLAUDE.md Before/After](https://gist.github.com/yurukusa/f9d7df5930bfb6d36a25673e69720f7e) — 40% token reduction through better writing patterns
524
+ - [Token Savings Cheat Card](https://gist.github.com/yurukusa/cfe44bfbb3756eccaf51660466913a2d) — 5 techniques to cut consumption in half
525
+ - [Token Consumption Checklist](https://gist.github.com/yurukusa/db8700a9f9fa331d36664df2868274cb) — 10-item diagnostic
526
+ - [Outage Survival Kit](https://gist.github.com/yurukusa/a0e31171eecb527d0df1d5498bf5f5d0) — what to do when Claude Code is down
527
+ - [CLAUDE.md Token Optimizer](https://gist.github.com/yurukusa/2b98fd2e90c0c13f6918c9f915e08e27) — 35-line template, 40% token reduction (800h tested)
528
+ - [Worktree Safety Hooks](https://gist.github.com/yurukusa/98bd43c5d0d8a6ebbf2cf21bfc1e2907) — 3 hooks to protect against worktree deletion and cross-tree destruction
529
+ - [Opus 4.7 Emergency Checklist](https://gist.github.com/yurukusa/c95efaee4b670e067369ece08092960c) — token burn diagnosis + immediate fixes
530
+ - [Cache TTL Mitigation Guide](https://gist.github.com/yurukusa/178d3949cd2bd6fbfc275b408f9711d4) — #46829 cache TTL change (1h→5m) impact and 4 mitigations
531
+ - [Security Checkup Hooks](https://gist.github.com/yurukusa/81f79ae6d760b27c17f2cd642ea846d7) — 4 hooks for financial, PII, deny bypass, and background task protection
532
+ - [Cache Breakage Fix](https://gist.github.com/yurukusa/fe6ba0a6aee14207f27ecc84419878b4) — 2 root causes of prompt cache invalidation (#47107 git status, #47098 session restart)
533
+ - [CLAUDE.md Token Optimization Cheat Sheet](https://gist.github.com/yurukusa/556f67c493a2729ce9b1703f5003a227) — 5 CLAUDE.md patterns that reduce token consumption with before/after examples
534
+ - [Token Troubleshooting Guide](https://gist.github.com/yurukusa/47b8c3eadb77cf74946f450f992ddac2) — fix quota drain, cache bugs, 1M context trap. Symptom-based diagnosis with latest issue references
535
+ - [Token Optimization Guide (English)](https://gist.github.com/yurukusa/70ff830c0ad3dff83e53be26cd80bd0a) — 3 biggest token levers with hook code, practical walkthrough
536
+ - [Token Book Sampler: 5 Techniques](https://gist.github.com/yurukusa/4a867ba301b480f996c5b76e4b6a6fbc) — free preview of the Token Book — 5 immediate techniques to reduce consumption
537
+ - [Token Optimization Checklist](https://gist.github.com/yurukusa/4b75025beee916f9904f56b79eeb1217) — 10-step checklist to cut token consumption in half, with hook configs
538
+ - [3 Things That Actually Work](https://gist.github.com/yurukusa/621f6d1cc35816df3da2e07876b44e16) — CLAUDE.md sizing, cache TTL, subagent control — based on 800h data
539
+ - [Cache TTL Diagnostic](https://gist.github.com/yurukusa/3a5bdcfdd295bef17b3ee00978b299f2) — 3 patterns that break prompt cache + fixes
540
+ - [Token Book Ch.1 Free Preview](https://gist.github.com/yurukusa/de862573f18d1a0a68d411b696dbcb73) — Where are your Claude Code tokens going? The 4 layers of token consumption explained
541
+ - [Deny Rules Break After 50 Subcommands](https://gist.github.com/yurukusa/0463d240d7b725218289a556414c72a5) — the hook that fixes Claude Code's deny rule bypass vulnerability
542
+ - [Opus 4.7 Emergency Kit](https://gist.github.com/yurukusa/1970b20fed95a682b72eb6e857e61d30) — 5 commands to protect your data from Opus 4.7 regressions (auto mode broken, 23+ data loss incidents)
543
+ - [cache_read Billing Bug Guide](https://gist.github.com/yurukusa/d5dc731dbc69e3ca92d69832bed641cb) — Opus 4.7 cache_read billed at full rate. Anthropic confirmed. Max plan users losing quota 3-6x faster
544
+ - [Opus 4.7 Survival Guide Summary](https://gist.github.com/yurukusa/5d66f0bcfe3fbfc73e6db106e10c533d) — 50 known issues with quick reference table, free diagnostic tools, and one-command fix
545
+ - [Opus 4.7 Known Issues Quick Reference](https://gist.github.com/yurukusa/2c1effab34a7554130d2704fdac59dff) — 26 issues / 43+ GitHub bugs in one table. Severity ratings and direct issue links
546
+ - [4 New Critical Issues (April 18)](https://gist.github.com/yurukusa/37c19b5b7f50fd8bbbeda5e1336c352e) — DoS via recursive spawn, subagent OOM, billing mismatch, UI/CLI model mismatch
547
+ - [トークン消費を半分にする方法](https://gist.github.com/yurukusa/bf4040a905148d9ca02898a53185fae1) — 800時間の実測データ+設定テンプレート(日本語)
548
+ - [How to Cut Token Usage in Half](https://gist.github.com/yurukusa/704d5cf9874f553dad5c46fccf53b09f) — 800h real data + config templates (English)
549
+ - [Compaction Triple Threat](https://gist.github.com/yurukusa/aa15f2065199c6fac4dcd3796fbaf90f) — 3 compaction bugs active simultaneously (#50402 + #50467 + #50492)
550
+ - [Sandbox Relative Path Bug (CRITICAL)](https://gist.github.com/yurukusa/a98efb6c561f92c82bcd49125af3b32a) — denyWrite/denyRead silently ignores relative paths (#50454)
551
+ - [27 Token Symptoms Quick Reference](https://gist.github.com/yurukusa/03a379854fa0f8eca091a75f7aab593b) — all 27 known token failure modes with top 5 killers table and April 2026 new symptoms
552
+ - [Token Saving Checklist (15 Items)](https://gist.github.com/yurukusa/6bd0d0a38a4887fc36475dd1f765ecd1) — ordered by impact: critical (30-50%), important (10-20%), good practice (5-10%)
553
+ - [Opus 4.7 Survival Cheatsheet](https://gist.github.com/yurukusa/f2d6e261338eeda70f0ed9507f995c13) — 46 known problems, quick fixes under 60 seconds, full reference table
554
+
555
+ ### Professional Services
556
+
557
+ Need help configuring Claude Code safely? [**Safety Setup Service**](https://yurukusa.github.io/cc-safe-setup/services.html) — audit, token optimization, and custom hooks by the cc-safe-setup team.
558
+
448
559
  ## FAQ
449
560
 
450
561
  **Q: I installed hooks but Claude says "Unknown skill: claude-code-hooks:setup"**
@@ -471,6 +582,14 @@ Since v2.1.78, protected directories always prompt regardless of permission mode
471
582
 
472
583
  `allow` takes precedence over `ask`. If you allow all Bash, ask rules are ignored ([#6527](https://github.com/anthropics/claude-code/issues/6527)). Use PreToolUse hooks to block dangerous commands instead of relying on the ask/allow priority system.
473
584
 
585
+ **Q: Hooks silently fail on macOS (Homebrew `jq` not found)**
586
+
587
+ Claude Code runs hooks with a restricted PATH that excludes `/opt/homebrew/bin` ([#46954](https://github.com/anthropics/claude-code/issues/46954)). If `jq` is installed via Homebrew, hooks silently exit 0. Fix: add `export PATH="/opt/homebrew/bin:$PATH"` at the top of your hook script, or use absolute paths like `/opt/homebrew/bin/jq`. Inline hooks in `settings.json` may also be affected — add a PATH export prefix: `export PATH="/opt/homebrew/bin:$PATH"; INPUT=$(cat); ...`
588
+
589
+ **Q: How is this different from [claude-token-efficient](https://github.com/drona23/claude-token-efficient)?**
590
+
591
+ Different goals. claude-token-efficient optimizes CLAUDE.md to make Claude's responses shorter and cheaper. cc-safe-setup prevents dangerous operations (file deletion, credential leaks, force-push). They work well together: use claude-token-efficient for cost reduction, cc-safe-setup for safety. For comprehensive token optimization beyond CLAUDE.md (hooks, context management, workflow design), see the [Token Book](https://yurukusa.github.io/cc-safe-setup/token-book.html).
592
+
474
593
  **Still stuck?** See the full [Permission Troubleshooting Flowchart](https://gist.github.com/yurukusa/b64217ffcb908fa309dbfcfa368cd84d) for step-by-step diagnosis.
475
594
 
476
595
  ## Contributing
@@ -486,6 +605,8 @@ Since v2.1.78, protected directories always prompt regardless of permission mode
486
605
 
487
606
  **Share your experience:** Used cc-safe-setup and have feedback? Open a discussion or comment on any issue. We read everything.
488
607
 
608
+ If cc-safe-setup saved you from a disaster (or just saved you time), a ⭐ helps others find it too.
609
+
489
610
  ## Also by yurukusa
490
611
 
491
612
  - [quiet life](https://yurukusa.github.io/quiet-life/) — Touch the dark. Something alive appears
@@ -280,3 +280,5 @@ Run `npx cc-safe-setup --doctor` for automated diagnosis.
280
280
  - [COOKBOOK.md](https://github.com/yurukusa/claude-code-hooks/blob/main/COOKBOOK.md) — 20 hook recipes
281
281
  - [Migration Guide](MIGRATION.md) — from permissions to hooks
282
282
  - [Ecosystem Comparison](https://yurukusa.github.io/cc-safe-setup/ecosystem.html) — all hook projects
283
+ - [Token Checkup](https://yurukusa.github.io/cc-safe-setup/token-checkup.html) — free 30-second token diagnostic
284
+ - [Token Book](https://zenn.dev/yurukusa/books/token-savings-guide) — cut your token consumption in half (¥2,500, chapter 1 free)
package/SKILL.md ADDED
@@ -0,0 +1,47 @@
1
+ ---
2
+ name: cc-safe-setup
3
+ description: Safety hooks for Claude Code — 700 pre-built hooks that prevent file deletion, credential leaks, git disasters, and token waste during autonomous AI coding sessions. 9,200+ tests. Install with npx cc-safe-setup.
4
+ ---
5
+
6
+ # cc-safe-setup
7
+
8
+ Safety-first configuration for Claude Code. Prevents the accidents that happen when AI writes code autonomously.
9
+
10
+ ## What it does
11
+
12
+ Installs pre-built safety hooks into your Claude Code environment. These hooks run automatically before/after tool calls to block dangerous operations.
13
+
14
+ **Categories:**
15
+ - **File protection**: Block `rm -rf`, prevent overwriting files outside project
16
+ - **Git safety**: Prevent force-push to main, block `reset --hard`
17
+ - **Credential guards**: Stop `.env` files from being committed or read by AI
18
+ - **Token optimization**: Warn on large file reads, limit subagent spawning
19
+ - **Quality gates**: Detect lazy rewrites, verify claims before committing
20
+
21
+ ## Quick start
22
+
23
+ ```bash
24
+ npx cc-safe-setup
25
+ ```
26
+
27
+ This runs an interactive wizard that configures hooks based on your risk profile.
28
+
29
+ ## Install individual hooks
30
+
31
+ ```bash
32
+ npx cc-safe-setup --install-example large-read-guard
33
+ npx cc-safe-setup --install-example prevent-rm-rf
34
+ npx cc-safe-setup --install-example git-force-push-block
35
+ ```
36
+
37
+ ## Why hooks instead of CLAUDE.md rules
38
+
39
+ Rules in CLAUDE.md are suggestions — Claude can forget them. Hooks are enforced at the system level. A hook that blocks `rm -rf` cannot be overridden by the AI.
40
+
41
+ From 800+ hours of autonomous operation: the hooks that matter most are the ones you don't notice until something goes wrong.
42
+
43
+ ## Resources
44
+
45
+ - Repository: https://github.com/yurukusa/cc-safe-setup
46
+ - Hook Selector (find hooks for your setup): https://yurukusa.github.io/cc-safe-setup/hook-selector.html
47
+ - Token Checkup (diagnose waste): https://yurukusa.github.io/cc-safe-setup/token-checkup.html
@@ -335,6 +335,32 @@ This prevents `ToolSearch` deferred loading and preserves the cache prefix acros
335
335
 
336
336
  **Related issues**: [#41249](https://github.com/anthropics/claude-code/issues/41249), [#41788](https://github.com/anthropics/claude-code/issues/41788), [#38335](https://github.com/anthropics/claude-code/issues/38335), [#40524](https://github.com/anthropics/claude-code/issues/40524), [#41617](https://github.com/anthropics/claude-code/issues/41617)
337
337
 
338
+ ## Multiple Hook Sources: stdin Race Condition
339
+
340
+ **Symptom**: Safety hooks appear installed but don't block dangerous commands. No errors, no warnings — hooks just silently allow everything.
341
+
342
+ **Root cause**: When multiple `PreToolUse` hooks match the same tool (e.g., two hooks both matching `Bash`), only the first hook receives stdin. The second hook gets empty input, all guard conditions fail, and it exits 0 (allow). This is an upstream Claude Code bug ([#42702](https://github.com/anthropics/claude-code/issues/42702)).
343
+
344
+ **When this happens**:
345
+ - cc-safe-setup hooks + another hook provider (e.g., project-level `.claude/settings.json` hooks)
346
+ - cc-safe-setup hooks + manually added hooks in `~/.claude/settings.json` that match the same trigger
347
+
348
+ **When this does NOT happen**:
349
+ - cc-safe-setup is the only hook source (default install)
350
+
351
+ **How to verify your hooks receive input**:
352
+
353
+ Add a temporary debug line to the top of a hook:
354
+
355
+ ```bash
356
+ INPUT=$(cat)
357
+ echo "DEBUG: input length = ${#INPUT}" >&2
358
+ ```
359
+
360
+ If you see `input length = 0`, that hook is not receiving stdin.
361
+
362
+ **Workaround**: Ensure only one hook source matches each trigger+matcher combination. If you need multiple hooks on the same trigger, combine them into a single script.
363
+
338
364
  ## Still Stuck?
339
365
 
340
366
  1. Wrap the hook with debug wrapper: `npx cc-safe-setup --install-example hook-debug-wrapper`
@@ -1,6 +1,6 @@
1
1
  # Example Hooks
2
2
 
3
- 518 installable hooks. Each solves a real problem from GitHub Issues or autonomous operation. 7,603 tests.
3
+ 675 installable hooks. Each solves a real problem from GitHub Issues or autonomous operation. 9,200+ tests.
4
4
 
5
5
  ```bash
6
6
  npx cc-safe-setup --install-example <name> # install one
@@ -39,6 +39,16 @@ npx cc-safe-setup --shield # install recommended set
39
39
  - [OWASP MCP Top 10 Defense](https://yurukusa.github.io/cc-safe-setup/owasp-mcp-hooks.html)
40
40
  - [COOKBOOK](../COOKBOOK.md)
41
41
 
42
+ ## Token Optimization
43
+
44
+ Using too many tokens? These hooks help monitor and reduce consumption:
45
+
46
+ - **`token-budget-guard`** — Alert when session exceeds token budget
47
+ - **`large-read-guard`** — Block reading files over 1000 lines
48
+ - **`context-monitor`** — Track context window usage
49
+
50
+ For a complete guide: [Token Book](https://zenn.dev/yurukusa/books/token-savings-guide) — cut token consumption in half with templates and measured data (¥2,500, chapter 1 free). Or try the [free diagnostic](https://yurukusa.github.io/cc-safe-setup/token-checkup.html).
51
+
42
52
  ## Write Your Own
43
53
 
44
54
  See [CONTRIBUTING.md](../CONTRIBUTING.md).
@@ -0,0 +1,58 @@
1
+ #!/bin/bash
2
+ # activity-logger.sh — Log all tool uses to JSONL for audit and debugging
3
+ #
4
+ # Solves: "What did Claude do overnight?" — no activity trail after long sessions
5
+ # Also useful for: error tracking, cost analysis, compliance auditing
6
+ #
7
+ # Records every tool call with timestamp, tool name, and key metadata.
8
+ # Error patterns in Bash output are flagged for downstream guards.
9
+ #
10
+ # Usage: Add to settings.json as a PostToolUse hook
11
+ #
12
+ # {
13
+ # "hooks": {
14
+ # "PostToolUse": [{
15
+ # "matcher": "",
16
+ # "hooks": [{ "type": "command", "command": "bash ~/.claude/hooks/activity-logger.sh" }]
17
+ # }]
18
+ # }
19
+ # }
20
+ #
21
+ # Output: ~/.claude/activity-log.jsonl
22
+ # Each line is a JSON object with ts, tool, and tool-specific fields.
23
+
24
+ set -u
25
+
26
+ INPUT=$(cat)
27
+ TOOL=$(printf '%s' "$INPUT" | jq -r '.tool_name // empty' 2>/dev/null)
28
+ [ -z "$TOOL" ] && exit 0
29
+
30
+ LOG_FILE="${HOME}/.claude/activity-log.jsonl"
31
+ TS=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
32
+
33
+ case "$TOOL" in
34
+ Edit|Write)
35
+ FILE=$(printf '%s' "$INPUT" | jq -r '.tool_input.file_path // empty' 2>/dev/null)
36
+ printf '{"ts":"%s","tool":"%s","file":"%s"}\n' "$TS" "$TOOL" "$FILE" >> "$LOG_FILE"
37
+ ;;
38
+ Bash)
39
+ CMD=$(printf '%s' "$INPUT" | jq -r '.tool_input.command // empty' 2>/dev/null | head -c 200)
40
+ STDOUT=$(printf '%s' "$INPUT" | jq -r '.stdout // empty' 2>/dev/null | head -c 500)
41
+ EXIT_CODE=$(printf '%s' "$INPUT" | jq -r '.tool_result.exit_code // "0"' 2>/dev/null)
42
+ ERROR_PATTERN=""
43
+ if echo "$STDOUT" | grep -qiE '(error|ENOENT|EACCES|EPERM|fatal|panic|segfault)'; then
44
+ ERROR_PATTERN=$(echo "$STDOUT" | grep -oiE '(error|ENOENT|EACCES|EPERM|fatal|panic|segfault)' | head -1)
45
+ fi
46
+ printf '{"ts":"%s","tool":"%s","cmd":"%s","exit_code":%s,"error_pattern":"%s"}\n' \
47
+ "$TS" "$TOOL" "$(echo "$CMD" | tr '"' "'")" "$EXIT_CODE" "$ERROR_PATTERN" >> "$LOG_FILE"
48
+ ;;
49
+ Read)
50
+ FILE=$(printf '%s' "$INPUT" | jq -r '.tool_input.file_path // empty' 2>/dev/null)
51
+ printf '{"ts":"%s","tool":"%s","file":"%s"}\n' "$TS" "$TOOL" "$FILE" >> "$LOG_FILE"
52
+ ;;
53
+ *)
54
+ printf '{"ts":"%s","tool":"%s"}\n' "$TS" "$TOOL" >> "$LOG_FILE"
55
+ ;;
56
+ esac
57
+
58
+ exit 0
@@ -25,8 +25,9 @@ if echo "$FILE_PATH" | grep -qE '\.claude/'; then
25
25
  jq -n '{
26
26
  hookSpecificOutput: {
27
27
  hookEventName: "PermissionRequest",
28
- permissionDecision: "allow",
29
- permissionDecisionReason: "Allowed: .claude/ directory (isolated environment)"
28
+ decision: {
29
+ behavior: "allow"
30
+ }
30
31
  }
31
32
  }'
32
33
  exit 0
@@ -21,8 +21,9 @@ if echo "$FILE_PATH" | grep -qE '\.git/hooks/[^/]+$'; then
21
21
  jq -n '{
22
22
  hookSpecificOutput: {
23
23
  hookEventName: "PermissionRequest",
24
- permissionDecision: "allow",
25
- permissionDecisionReason: "Allowed: git hooks directory"
24
+ decision: {
25
+ behavior: "allow"
26
+ }
26
27
  }
27
28
  }'
28
29
  exit 0
@@ -24,8 +24,9 @@ if echo "$FILE_PATH" | grep -qE '\.(claude|git|vscode|idea)/'; then
24
24
  jq -n '{
25
25
  hookSpecificOutput: {
26
26
  hookEventName: "PermissionRequest",
27
- permissionDecision: "allow",
28
- permissionDecisionReason: "Allowed: protected directory (full bypass)"
27
+ decision: {
28
+ behavior: "allow"
29
+ }
29
30
  }
30
31
  }'
31
32
  exit 0
@@ -15,6 +15,9 @@
15
15
  # See: https://github.com/anthropics/claude-code/issues/30519
16
16
  # See: https://github.com/anthropics/claude-code/issues/16561
17
17
  #
18
+ # Auto-approve hooks reduce token waste from permission prompts.
19
+ # For more token optimization patterns: https://zenn.dev/yurukusa/books/token-savings-guide
20
+ #
18
21
  # TRIGGER: PermissionRequest MATCHER: ""
19
22
 
20
23
  INPUT=$(cat)