cc-safe-setup 1.8.1 → 1.8.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 +2 -0
- package/examples/auto-snapshot.sh +51 -0
- package/index.mjs +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -138,6 +138,8 @@ Need custom hooks beyond the 8 built-in ones? See [`examples/`](examples/) for r
|
|
|
138
138
|
- **auto-approve-build.sh** — Auto-approve npm/yarn/cargo/go/python build, test, and lint commands
|
|
139
139
|
- **auto-approve-docker.sh** — Auto-approve docker build, compose, ps, logs, and other safe commands
|
|
140
140
|
- **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))
|
|
141
|
+
- **auto-approve-python.sh** — Auto-approve pytest, mypy, ruff, black, isort, flake8, pylint commands
|
|
142
|
+
- **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))
|
|
141
143
|
|
|
142
144
|
## Learn More
|
|
143
145
|
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# auto-snapshot.sh — Automatic file snapshots before every edit
|
|
3
|
+
#
|
|
4
|
+
# Solves: Claude reverting verified changes after encountering
|
|
5
|
+
# contradictory information (sycophantic capitulation)
|
|
6
|
+
# (#37386, #37457)
|
|
7
|
+
#
|
|
8
|
+
# How it works:
|
|
9
|
+
# - Runs as a PreToolUse hook on Edit/Write
|
|
10
|
+
# - Copies the file to ~/.claude/snapshots/ before modification
|
|
11
|
+
# - When Claude walks back correct work, diff the snapshot
|
|
12
|
+
# against the current file and restore
|
|
13
|
+
#
|
|
14
|
+
# Usage: Add to settings.json as a PreToolUse hook
|
|
15
|
+
#
|
|
16
|
+
# {
|
|
17
|
+
# "hooks": {
|
|
18
|
+
# "PreToolUse": [{
|
|
19
|
+
# "matcher": "",
|
|
20
|
+
# "hooks": [{ "type": "command", "command": "~/.claude/hooks/auto-snapshot.sh" }]
|
|
21
|
+
# }]
|
|
22
|
+
# }
|
|
23
|
+
# }
|
|
24
|
+
|
|
25
|
+
INPUT=$(cat)
|
|
26
|
+
TOOL=$(echo "$INPUT" | jq -r '.tool_name // empty' 2>/dev/null)
|
|
27
|
+
FILE=$(echo "$INPUT" | jq -r '.tool_input.file_path // empty' 2>/dev/null)
|
|
28
|
+
|
|
29
|
+
# Only snapshot Edit and Write operations
|
|
30
|
+
if [[ "$TOOL" != "Edit" && "$TOOL" != "Write" ]]; then
|
|
31
|
+
exit 0
|
|
32
|
+
fi
|
|
33
|
+
|
|
34
|
+
# Only snapshot existing files (Write to new files has nothing to save)
|
|
35
|
+
if [[ -z "$FILE" || ! -f "$FILE" ]]; then
|
|
36
|
+
exit 0
|
|
37
|
+
fi
|
|
38
|
+
|
|
39
|
+
SNAP_DIR="$HOME/.claude/snapshots/$(date +%Y%m%d)"
|
|
40
|
+
mkdir -p "$SNAP_DIR" 2>/dev/null
|
|
41
|
+
|
|
42
|
+
# Use filename + timestamp to avoid collisions
|
|
43
|
+
BASENAME=$(basename "$FILE")
|
|
44
|
+
TIMESTAMP=$(date +%H%M%S)
|
|
45
|
+
cp "$FILE" "$SNAP_DIR/${BASENAME}.${TIMESTAMP}" 2>/dev/null
|
|
46
|
+
|
|
47
|
+
# Keep snapshots manageable — delete files older than 7 days
|
|
48
|
+
find "$HOME/.claude/snapshots" -type f -mtime +7 -delete 2>/dev/null
|
|
49
|
+
find "$HOME/.claude/snapshots" -type d -empty -delete 2>/dev/null
|
|
50
|
+
|
|
51
|
+
exit 0
|
package/index.mjs
CHANGED
|
@@ -262,6 +262,7 @@ function examples() {
|
|
|
262
262
|
'enforce-tests.sh': 'Warn when source files change without test files',
|
|
263
263
|
'notify-waiting.sh': 'Desktop notification when Claude waits for input',
|
|
264
264
|
'auto-approve-python.sh': 'Auto-approve pytest, mypy, ruff, black, isort commands',
|
|
265
|
+
'auto-snapshot.sh': 'Auto-save file snapshots before edits (rollback protection)',
|
|
265
266
|
};
|
|
266
267
|
|
|
267
268
|
console.log();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cc-safe-setup",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.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": {
|