cc-safe-setup 3.1.0 → 3.2.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
@@ -220,6 +220,10 @@ Or browse all available examples in [`examples/`](examples/):
220
220
 
221
221
  **[SAFETY_CHECKLIST.md](SAFETY_CHECKLIST.md)** — Copy-paste checklist for before/during/after autonomous sessions.
222
222
 
223
+ ## settings.json Reference
224
+
225
+ **[SETTINGS_REFERENCE.md](SETTINGS_REFERENCE.md)** — Complete reference for permissions, hooks, modes, and common configurations. Includes known limitations and workarounds.
226
+
223
227
  ## Migration Guide
224
228
 
225
229
  **[MIGRATION.md](MIGRATION.md)** — Step-by-step guide for moving from permissions-only to permissions + hooks. Keep your existing config, add safety layers on top.
@@ -0,0 +1,282 @@
1
+ # Claude Code settings.json Reference
2
+
3
+ Everything you can put in `~/.claude/settings.json`, documented from real usage and GitHub Issues.
4
+
5
+ ## File Locations
6
+
7
+ | File | Scope | Precedence |
8
+ |------|-------|------------|
9
+ | `~/.claude/settings.json` | All projects (user-level) | Lowest |
10
+ | `.claude/settings.json` | Current project | Overrides user |
11
+ | `.claude/settings.local.json` | Current project (gitignored) | Highest |
12
+
13
+ ## Permissions
14
+
15
+ ### allow
16
+
17
+ Commands that auto-execute without prompting.
18
+
19
+ ```json
20
+ {
21
+ "permissions": {
22
+ "allow": [
23
+ "Bash(git status:*)",
24
+ "Bash(git log:*)",
25
+ "Bash(git diff:*)",
26
+ "Bash(npm test:*)",
27
+ "Bash(npm run:*)",
28
+ "Read(*)",
29
+ "Edit(*)",
30
+ "Write(*)",
31
+ "Glob(*)",
32
+ "Grep(*)"
33
+ ]
34
+ }
35
+ }
36
+ ```
37
+
38
+ **Pattern syntax:**
39
+ - `Tool(pattern)` — match tool name and argument pattern
40
+ - `*` — wildcard (matches anything)
41
+ - `:` — separator between command and arguments
42
+ - `Bash(git:*)` — any command starting with `git`
43
+ - `Bash(git status:*)` — `git status` with any args
44
+ - `Bash(*)` — all bash commands (dangerous — use with hooks)
45
+
46
+ **Known limitations (as of v2.1.81):**
47
+ - Compound commands don't match: `Bash(git:*)` won't match `cd /path && git log` ([#30519](https://github.com/anthropics/claude-code/issues/30519), [#16561](https://github.com/anthropics/claude-code/issues/16561))
48
+ - "Always Allow" saves exact strings, not patterns ([#6850](https://github.com/anthropics/claude-code/issues/6850))
49
+ - User-level settings may not apply at project level ([#5140](https://github.com/anthropics/claude-code/issues/5140))
50
+ - **Workaround:** Use `compound-command-approver` hook: `npx cc-safe-setup --install-example compound-command-approver`
51
+
52
+ ### deny
53
+
54
+ Commands that are always blocked.
55
+
56
+ ```json
57
+ {
58
+ "permissions": {
59
+ "deny": [
60
+ "Bash(rm -rf:*)",
61
+ "Bash(git push --force:*)",
62
+ "Bash(sudo:*)"
63
+ ]
64
+ }
65
+ }
66
+ ```
67
+
68
+ **Note:** Deny rules have the same compound-command limitation as allow rules. Hooks are more reliable for blocking.
69
+
70
+ ## Hooks
71
+
72
+ ### Structure
73
+
74
+ ```json
75
+ {
76
+ "hooks": {
77
+ "PreToolUse": [
78
+ {
79
+ "matcher": "Bash",
80
+ "hooks": [
81
+ {
82
+ "type": "command",
83
+ "command": "~/.claude/hooks/my-hook.sh"
84
+ }
85
+ ]
86
+ }
87
+ ]
88
+ }
89
+ }
90
+ ```
91
+
92
+ ### Hook Events
93
+
94
+ | Event | When | Use Case |
95
+ |-------|------|----------|
96
+ | `PreToolUse` | Before tool executes | Block/modify commands |
97
+ | `PostToolUse` | After tool executes | Validate output, check syntax |
98
+ | `Stop` | Session ends | Log data, notify |
99
+ | `UserPromptSubmit` | User presses Enter | Validate prompts |
100
+ | `Notification` | Claude shows notification | Custom alerts |
101
+ | `PreCompact` | Before context compaction | Save state |
102
+ | `SessionStart` | Session begins | Initialize |
103
+ | `SessionEnd` | Session ends | Cleanup |
104
+
105
+ ### Matcher Values
106
+
107
+ | Matcher | Matches |
108
+ |---------|---------|
109
+ | `"Bash"` | Bash tool only |
110
+ | `"Edit\|Write"` | Edit or Write tool |
111
+ | `"Read"` | Read tool only |
112
+ | `""` (empty) | All tools |
113
+
114
+ ### Hook Exit Codes
115
+
116
+ | Code | Meaning |
117
+ |------|---------|
118
+ | 0 | Allow (or no opinion) |
119
+ | 2 | **Block** — tool call cancelled |
120
+ | Other | Error (treated as allow) |
121
+
122
+ ### Hook Input (stdin JSON)
123
+
124
+ **PreToolUse/PostToolUse:**
125
+ ```json
126
+ {
127
+ "tool_name": "Bash",
128
+ "tool_input": {
129
+ "command": "git push origin main"
130
+ }
131
+ }
132
+ ```
133
+
134
+ **For Edit/Write:**
135
+ ```json
136
+ {
137
+ "tool_name": "Edit",
138
+ "tool_input": {
139
+ "file_path": "/path/to/file.py",
140
+ "old_string": "...",
141
+ "new_string": "..."
142
+ }
143
+ }
144
+ ```
145
+
146
+ **Stop:**
147
+ ```json
148
+ {
149
+ "stop_reason": "user",
150
+ "hook_event_name": "Stop"
151
+ }
152
+ ```
153
+
154
+ ### Hook Output (stdout JSON)
155
+
156
+ **Auto-approve:**
157
+ ```json
158
+ {
159
+ "hookSpecificOutput": {
160
+ "hookEventName": "PreToolUse",
161
+ "permissionDecision": "allow",
162
+ "permissionDecisionReason": "auto-approved by hook"
163
+ }
164
+ }
165
+ ```
166
+
167
+ **Modify input:**
168
+ ```json
169
+ {
170
+ "hookSpecificOutput": {
171
+ "hookEventName": "PreToolUse",
172
+ "updatedInput": {
173
+ "command": "modified command here"
174
+ }
175
+ }
176
+ }
177
+ ```
178
+
179
+ ## defaultMode
180
+
181
+ ```json
182
+ {
183
+ "defaultMode": "default"
184
+ }
185
+ ```
186
+
187
+ | Mode | Behavior |
188
+ |------|----------|
189
+ | `"default"` | Prompt for unrecognized commands |
190
+ | `"dontAsk"` | Auto-approve everything (hooks still run) |
191
+ | `"bypassPermissions"` | Skip everything including hooks (dangerous) |
192
+
193
+ **Recommendation:** Use `"dontAsk"` + hooks instead of `"bypassPermissions"`.
194
+
195
+ ## Common Configurations
196
+
197
+ ### Minimal Safe Setup
198
+
199
+ ```json
200
+ {
201
+ "permissions": {
202
+ "allow": ["Read(*)", "Glob(*)", "Grep(*)"]
203
+ },
204
+ "hooks": {
205
+ "PreToolUse": [
206
+ {
207
+ "matcher": "Bash",
208
+ "hooks": [
209
+ { "type": "command", "command": "~/.claude/hooks/destructive-guard.sh" },
210
+ { "type": "command", "command": "~/.claude/hooks/branch-guard.sh" }
211
+ ]
212
+ }
213
+ ]
214
+ }
215
+ }
216
+ ```
217
+
218
+ ### Autonomous Operation
219
+
220
+ ```json
221
+ {
222
+ "defaultMode": "dontAsk",
223
+ "permissions": {
224
+ "allow": ["Bash(*)", "Read(*)", "Edit(*)", "Write(*)", "Glob(*)", "Grep(*)"]
225
+ },
226
+ "hooks": {
227
+ "PreToolUse": [
228
+ {
229
+ "matcher": "Bash",
230
+ "hooks": [
231
+ { "type": "command", "command": "~/.claude/hooks/destructive-guard.sh" },
232
+ { "type": "command", "command": "~/.claude/hooks/branch-guard.sh" },
233
+ { "type": "command", "command": "~/.claude/hooks/secret-guard.sh" },
234
+ { "type": "command", "command": "~/.claude/hooks/compound-command-approver.sh" }
235
+ ]
236
+ }
237
+ ],
238
+ "PostToolUse": [
239
+ {
240
+ "matcher": "Edit|Write",
241
+ "hooks": [
242
+ { "type": "command", "command": "~/.claude/hooks/syntax-check.sh" }
243
+ ]
244
+ },
245
+ {
246
+ "matcher": "",
247
+ "hooks": [
248
+ { "type": "command", "command": "~/.claude/hooks/context-monitor.sh" }
249
+ ]
250
+ }
251
+ ]
252
+ }
253
+ }
254
+ ```
255
+
256
+ ### Generate This Automatically
257
+
258
+ ```bash
259
+ npx cc-safe-setup # Install hooks
260
+ npx cc-safe-setup --audit # Check your score
261
+ npx cc-safe-setup --doctor # Diagnose issues
262
+ ```
263
+
264
+ ## Troubleshooting
265
+
266
+ | Problem | Cause | Fix |
267
+ |---------|-------|-----|
268
+ | Hooks don't fire | Not registered in settings.json | `npx cc-safe-setup` |
269
+ | Hooks don't block | Wrong exit code (not 2) | Check `echo $?` after test |
270
+ | "jq: command not found" | jq not installed | `brew install jq` / `apt install jq` |
271
+ | Hook permission denied | Not executable | `chmod +x ~/.claude/hooks/*.sh` |
272
+ | Compound commands prompt | Permission system limitation | Install `compound-command-approver` |
273
+ | "Always Allow" doesn't stick | Saves exact string, not pattern | Use hooks instead |
274
+
275
+ Run `npx cc-safe-setup --doctor` for automated diagnosis.
276
+
277
+ ## Resources
278
+
279
+ - [Official Hooks Documentation](https://docs.anthropic.com/en/docs/claude-code/hooks)
280
+ - [COOKBOOK.md](https://github.com/yurukusa/claude-code-hooks/blob/main/COOKBOOK.md) — 20 hook recipes
281
+ - [Migration Guide](MIGRATION.md) — from permissions to hooks
282
+ - [Ecosystem Comparison](https://yurukusa.github.io/cc-safe-setup/ecosystem.html) — all hook projects
package/index.mjs CHANGED
@@ -79,6 +79,7 @@ const IMPORT_IDX = process.argv.findIndex(a => a === '--import');
79
79
  const IMPORT_FILE = IMPORT_IDX !== -1 ? process.argv[IMPORT_IDX + 1] : null;
80
80
  const STATS = process.argv.includes('--stats');
81
81
  const JSON_OUTPUT = process.argv.includes('--json');
82
+ const LINT = process.argv.includes('--lint');
82
83
  const CREATE_IDX = process.argv.findIndex(a => a === '--create');
83
84
  const CREATE_DESC = CREATE_IDX !== -1 ? process.argv.slice(CREATE_IDX + 1).join(' ') : null;
84
85
 
@@ -100,6 +101,7 @@ if (HELP) {
100
101
  npx cc-safe-setup --audit --json Machine-readable output for CI/CD
101
102
  npx cc-safe-setup --scan Detect tech stack, recommend hooks
102
103
  npx cc-safe-setup --learn Learn from your block history
104
+ npx cc-safe-setup --lint Static analysis of hook configuration
103
105
  npx cc-safe-setup --doctor Diagnose why hooks aren't working
104
106
  npx cc-safe-setup --watch Live dashboard of blocked commands
105
107
  npx cc-safe-setup --create "<desc>" Generate a custom hook from description
@@ -767,6 +769,148 @@ async function fullSetup() {
767
769
  console.log();
768
770
  }
769
771
 
772
+ async function lint() {
773
+ console.log();
774
+ console.log(c.bold + ' cc-safe-setup --lint' + c.reset);
775
+ console.log(c.dim + ' Static analysis of hook configuration...' + c.reset);
776
+ console.log();
777
+
778
+ if (!existsSync(SETTINGS_PATH)) {
779
+ console.log(c.red + ' No settings.json found.' + c.reset);
780
+ process.exit(1);
781
+ }
782
+
783
+ let settings;
784
+ try {
785
+ settings = JSON.parse(readFileSync(SETTINGS_PATH, 'utf-8'));
786
+ } catch (e) {
787
+ console.log(c.red + ' settings.json parse error: ' + e.message + c.reset);
788
+ process.exit(1);
789
+ }
790
+
791
+ let warnings = 0;
792
+ let errors = 0;
793
+ const warn = (msg) => { console.log(c.yellow + ' WARN: ' + c.reset + msg); warnings++; };
794
+ const error = (msg) => { console.log(c.red + ' ERROR: ' + c.reset + msg); errors++; };
795
+ const info = (msg) => { console.log(c.green + ' OK: ' + c.reset + msg); };
796
+
797
+ const hooks = settings.hooks || {};
798
+
799
+ // 1. Check for duplicate hook commands within same trigger
800
+ for (const [trigger, entries] of Object.entries(hooks)) {
801
+ const commands = [];
802
+ for (const entry of entries) {
803
+ for (const h of (entry.hooks || [])) {
804
+ if (h.command) {
805
+ if (commands.includes(h.command)) {
806
+ warn(trigger + ': duplicate hook "' + h.command.split('/').pop() + '"');
807
+ }
808
+ commands.push(h.command);
809
+ }
810
+ }
811
+ }
812
+ if (commands.length > 0 && new Set(commands).size === commands.length) {
813
+ info(trigger + ': no duplicates (' + commands.length + ' hooks)');
814
+ }
815
+ }
816
+
817
+ // 2. Check for empty matcher on PreToolUse (runs on every tool = slow)
818
+ for (const entry of (hooks.PreToolUse || [])) {
819
+ if (!entry.matcher || entry.matcher === '') {
820
+ const hookNames = (entry.hooks || []).map(h => (h.command || '').split('/').pop()).join(', ');
821
+ warn('PreToolUse hook with empty matcher runs on EVERY tool call: ' + hookNames);
822
+ }
823
+ }
824
+
825
+ // 3. Check for empty matcher on PostToolUse with heavy scripts
826
+ for (const entry of (hooks.PostToolUse || [])) {
827
+ if (!entry.matcher || entry.matcher === '') {
828
+ const hookNames = (entry.hooks || []).map(h => (h.command || '').split('/').pop()).join(', ');
829
+ // Check if any of these scripts are large (>5KB = potentially slow)
830
+ for (const h of (entry.hooks || [])) {
831
+ if (h.command) {
832
+ const resolved = h.command.replace(/^(bash|sh|node)\s+/, '').split(/\s+/)[0].replace(/^~/, HOME);
833
+ try {
834
+ const { statSync } = await import('fs');
835
+ const size = statSync(resolved).size;
836
+ if (size > 5000) {
837
+ warn('PostToolUse empty matcher + large script (' + (size/1024).toFixed(1) + 'KB): ' + resolved.split('/').pop());
838
+ }
839
+ } catch {}
840
+ }
841
+ }
842
+ }
843
+ }
844
+
845
+ // 4. Check for hooks that exist in settings but script is missing
846
+ for (const [trigger, entries] of Object.entries(hooks)) {
847
+ for (const entry of entries) {
848
+ for (const h of (entry.hooks || [])) {
849
+ if (h.command) {
850
+ let scriptPath = h.command.replace(/^(bash|sh|node|python3?)\s+/, '').split(/\s+/)[0];
851
+ scriptPath = scriptPath.replace(/^~/, HOME);
852
+ if (!existsSync(scriptPath)) {
853
+ error(trigger + ': missing script "' + scriptPath.split('/').pop() + '"');
854
+ }
855
+ }
856
+ }
857
+ }
858
+ }
859
+
860
+ // 5. Check for overly broad allow rules combined with no hooks
861
+ const allows = settings.permissions?.allow || [];
862
+ if (allows.includes('Bash(*)') && (hooks.PreToolUse || []).length === 0) {
863
+ error('Bash(*) in allow list with no PreToolUse hooks = no safety net');
864
+ } else if (allows.includes('Bash(*)') && (hooks.PreToolUse || []).length > 0) {
865
+ info('Bash(*) with PreToolUse hooks = hooks provide safety');
866
+ }
867
+
868
+ // 6. Check for conflicting allow and deny
869
+ const denies = settings.permissions?.deny || [];
870
+ for (const d of denies) {
871
+ if (allows.includes(d)) {
872
+ warn('Same pattern in both allow and deny: ' + d);
873
+ }
874
+ }
875
+
876
+ // 7. Check total hook count and warn about performance
877
+ let totalHooks = 0;
878
+ for (const entries of Object.values(hooks)) {
879
+ for (const entry of entries) {
880
+ totalHooks += (entry.hooks || []).length;
881
+ }
882
+ }
883
+ if (totalHooks > 20) {
884
+ warn(totalHooks + ' total hooks registered — may slow down tool calls');
885
+ } else if (totalHooks > 0) {
886
+ info(totalHooks + ' hooks registered');
887
+ }
888
+
889
+ // 8. Check for hooks without type: "command"
890
+ for (const [trigger, entries] of Object.entries(hooks)) {
891
+ for (const entry of entries) {
892
+ for (const h of (entry.hooks || [])) {
893
+ if (h.type !== 'command') {
894
+ warn(trigger + ': hook with type "' + h.type + '" (only "command" is supported)');
895
+ }
896
+ }
897
+ }
898
+ }
899
+
900
+ // Summary
901
+ console.log();
902
+ if (errors === 0 && warnings === 0) {
903
+ console.log(c.bold + c.green + ' Clean. No issues found.' + c.reset);
904
+ } else if (errors === 0) {
905
+ console.log(c.bold + c.yellow + ' ' + warnings + ' warning(s). No errors.' + c.reset);
906
+ } else {
907
+ console.log(c.bold + c.red + ' ' + errors + ' error(s), ' + warnings + ' warning(s).' + c.reset);
908
+ }
909
+ console.log();
910
+
911
+ process.exit(errors > 0 ? 1 : 0);
912
+ }
913
+
770
914
  async function createHook(description) {
771
915
  console.log();
772
916
  console.log(c.bold + ' cc-safe-setup --create' + c.reset);
@@ -1688,6 +1832,7 @@ async function main() {
1688
1832
  if (FULL) return fullSetup();
1689
1833
  if (DOCTOR) return doctor();
1690
1834
  if (WATCH) return watch();
1835
+ if (LINT) return lint();
1691
1836
  if (CREATE_DESC) return createHook(CREATE_DESC);
1692
1837
  if (STATS) return stats();
1693
1838
  if (EXPORT) return exportConfig();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cc-safe-setup",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "description": "One command to make Claude Code safe for autonomous operation. 8 built-in hooks + 27 installable examples. Destructive blocker, branch guard, compound command approver, database wipe protection, and more.",
5
5
  "main": "index.mjs",
6
6
  "bin": {