cc-safe-setup 1.9.0 → 1.9.2

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
@@ -128,7 +128,13 @@ Or start with the free hooks: [claude-code-hooks](https://github.com/yurukusa/cl
128
128
 
129
129
  ## Examples
130
130
 
131
- Need custom hooks beyond the 8 built-in ones? See [`examples/`](examples/) for ready-to-use recipes:
131
+ Need custom hooks beyond the 8 built-in ones? Install any example with one command:
132
+
133
+ ```bash
134
+ npx cc-safe-setup --install-example block-database-wipe
135
+ ```
136
+
137
+ Or browse all available examples in [`examples/`](examples/):
132
138
 
133
139
  - **auto-approve-git-read.sh** — Auto-approve `git status`, `git log`, even with `-C` flags
134
140
  - **auto-approve-ssh.sh** — Auto-approve safe SSH commands (`uptime`, `whoami`, etc.)
@@ -143,11 +149,12 @@ Need custom hooks beyond the 8 built-in ones? See [`examples/`](examples/) for r
143
149
  - **allowlist.sh** — Block everything not explicitly approved — inverse permission model ([#37471](https://github.com/anthropics/claude-code/issues/37471))
144
150
  - **protect-dotfiles.sh** — Block modifications to `~/.bashrc`, `~/.aws/`, `~/.ssh/` and chezmoi without diff ([#37478](https://github.com/anthropics/claude-code/issues/37478))
145
151
  - **scope-guard.sh** — Block file operations outside project directory — absolute paths, home, parent escapes ([#36233](https://github.com/anthropics/claude-code/issues/36233))
152
+ - **auto-checkpoint.sh** — Auto-commit after every edit for rollback protection ([#34674](https://github.com/anthropics/claude-code/issues/34674))
146
153
 
147
154
  ## Learn More
148
155
 
149
156
  - [Official Hooks Reference](https://code.claude.com/docs/en/hooks) — Claude Code hooks documentation
150
- - [Hooks Cookbook](https://github.com/yurukusa/claude-code-hooks/blob/main/COOKBOOK.md) — 13 ready-to-use recipes from real GitHub Issues
157
+ - [Hooks Cookbook](https://github.com/yurukusa/claude-code-hooks/blob/main/COOKBOOK.md) — 14 ready-to-use recipes from real GitHub Issues
151
158
  - [Japanese guide (Qiita)](https://qiita.com/yurukusa/items/a9714b33f5d974e8f1e8) — この記事の日本語解説
152
159
  - [The incident that inspired this tool](https://github.com/anthropics/claude-code/issues/36339) — NTFS junction rm -rf
153
160
 
@@ -5,6 +5,7 @@ Custom hooks beyond the 8 built-in ones. Copy any file to `~/.claude/hooks/` and
5
5
  | Hook | Purpose | Related Issue |
6
6
  |------|---------|---------------|
7
7
  | **allowlist.sh** | Block everything not explicitly approved (inverse model) | [#37471](https://github.com/anthropics/claude-code/issues/37471) |
8
+ | **auto-checkpoint.sh** | Auto-commit after edits for rollback protection | [#34674](https://github.com/anthropics/claude-code/issues/34674) |
8
9
  | **auto-approve-build.sh** | Auto-approve npm/yarn/cargo/go build, test, lint | |
9
10
  | **auto-approve-docker.sh** | Auto-approve docker build, compose, ps, logs | |
10
11
  | **auto-approve-git-read.sh** | Auto-approve `git status/log/diff` even with `-C` flags | [#36900](https://github.com/anthropics/claude-code/issues/36900) |
@@ -21,14 +22,16 @@ Custom hooks beyond the 8 built-in ones. Copy any file to `~/.claude/hooks/` and
21
22
  ## Quick Start
22
23
 
23
24
  ```bash
24
- # 1. Copy example to hooks directory
25
- cp examples/block-database-wipe.sh ~/.claude/hooks/
25
+ # One command copies hook, updates settings.json, makes executable
26
+ npx cc-safe-setup --install-example block-database-wipe
27
+ ```
26
28
 
27
- # 2. Make executable
28
- chmod +x ~/.claude/hooks/block-database-wipe.sh
29
+ Or manually:
29
30
 
30
- # 3. Add to settings.json
31
- # See each file's header comment for the JSON configuration
31
+ ```bash
32
+ cp examples/block-database-wipe.sh ~/.claude/hooks/
33
+ chmod +x ~/.claude/hooks/block-database-wipe.sh
34
+ # Add to settings.json — see each file's header for the JSON config
32
35
  ```
33
36
 
34
37
  ## List from CLI
@@ -0,0 +1,38 @@
1
+ #!/bin/bash
2
+ # auto-checkpoint.sh — Auto-commit after every edit for rollback protection
3
+ #
4
+ # Solves: Context compaction silently reverting uncommitted edits (#34674)
5
+ # Also protects against: session crashes, token expiry, any unexpected death
6
+ #
7
+ # Creates lightweight checkpoint commits after every Edit/Write.
8
+ # If anything goes wrong, you can recover with `git log` and `git cherry-pick`.
9
+ #
10
+ # Usage: Add to settings.json as a PostToolUse hook
11
+ #
12
+ # {
13
+ # "hooks": {
14
+ # "PostToolUse": [{
15
+ # "matcher": "Edit|Write",
16
+ # "hooks": [{ "type": "command", "command": "~/.claude/hooks/auto-checkpoint.sh" }]
17
+ # }]
18
+ # }
19
+ # }
20
+
21
+ INPUT=$(cat)
22
+ TOOL=$(echo "$INPUT" | jq -r '.tool_name // empty' 2>/dev/null)
23
+
24
+ # Only checkpoint after Edit or Write
25
+ [[ "$TOOL" != "Edit" && "$TOOL" != "Write" ]] && exit 0
26
+
27
+ # Must be in a git repo
28
+ git rev-parse --git-dir &>/dev/null || exit 0
29
+
30
+ # Only commit if there are actual changes
31
+ DIRTY=$(git status --porcelain 2>/dev/null | head -1)
32
+ [[ -z "$DIRTY" ]] && exit 0
33
+
34
+ # Create checkpoint commit
35
+ git add -A 2>/dev/null
36
+ git commit -m "checkpoint: auto-save $(date +%H:%M:%S)" --no-verify 2>/dev/null
37
+
38
+ exit 0
package/index.mjs CHANGED
@@ -179,6 +179,23 @@ function status() {
179
179
  console.log();
180
180
  console.log(' ' + (settingsOk ? c.green + '✓' : c.red + '✗') + c.reset + ' settings.json ' + (settingsOk ? 'has hooks configured' : 'missing hook configuration'));
181
181
 
182
+ // Check installed examples
183
+ const exampleFiles = [
184
+ 'allowlist.sh', 'auto-approve-build.sh', 'auto-approve-docker.sh',
185
+ 'auto-approve-git-read.sh', 'auto-approve-python.sh', 'auto-approve-ssh.sh',
186
+ 'auto-checkpoint.sh', 'auto-snapshot.sh', 'block-database-wipe.sh',
187
+ 'edit-guard.sh', 'enforce-tests.sh', 'notify-waiting.sh',
188
+ 'protect-dotfiles.sh', 'scope-guard.sh',
189
+ ];
190
+ const installedExamples = exampleFiles.filter(f => existsSync(join(HOOKS_DIR, f)));
191
+ if (installedExamples.length > 0) {
192
+ console.log();
193
+ console.log(' ' + c.bold + 'Example hooks installed:' + c.reset);
194
+ for (const f of installedExamples) {
195
+ console.log(' ' + c.green + '✓' + c.reset + ' ' + f);
196
+ }
197
+ }
198
+
182
199
  console.log();
183
200
  if (missing === 0) {
184
201
  console.log(c.bold + ' All ' + installed + ' hooks installed.' + c.reset);
@@ -186,6 +203,9 @@ function status() {
186
203
  console.log(c.bold + ' ' + installed + '/' + Object.keys(HOOKS).length + ' hooks installed.' + c.reset);
187
204
  console.log(' ' + c.dim + 'Run: npx cc-safe-setup' + c.reset);
188
205
  }
206
+ if (installedExamples.length > 0) {
207
+ console.log(' ' + c.dim + '+ ' + installedExamples.length + ' example hooks' + c.reset);
208
+ }
189
209
  console.log();
190
210
 
191
211
  // Exit code for CI: 0 = all installed, 1 = missing hooks
@@ -269,6 +289,7 @@ function examples() {
269
289
  'allowlist.sh': 'Block everything not in allowlist (inverse permission model)',
270
290
  'protect-dotfiles.sh': 'Block modifications to ~/.bashrc, ~/.aws/, ~/.ssh/',
271
291
  'scope-guard.sh': 'Block file operations outside project directory',
292
+ 'auto-checkpoint.sh': 'Auto-commit after edits for rollback protection',
272
293
  };
273
294
 
274
295
  console.log();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cc-safe-setup",
3
- "version": "1.9.0",
3
+ "version": "1.9.2",
4
4
  "description": "One command to make Claude Code safe for autonomous operation. 8 hooks: destructive blocker, branch guard, force-push protection, secret leak prevention, syntax checks, and more.",
5
5
  "main": "index.mjs",
6
6
  "bin": {