cc-safe-setup 11.8.0 → 12.1.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 +16 -1
- package/examples/git-remote-guard.sh +32 -0
- package/examples/subagent-scope-guard.sh +33 -0
- package/index.mjs +79 -0
- package/package.json +1 -1
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 + 104 examples = **118 hooks**.
|
|
9
|
+
8 built-in + 104 examples = **118 hooks**. 42 CLI commands. 561 tests. 5 languages. [**Hub**](https://yurukusa.github.io/cc-safe-setup/hub.html) · [Cheat Sheet](https://yurukusa.github.io/cc-safe-setup/hooks-cheatsheet.html) · [Builder](https://yurukusa.github.io/cc-safe-setup/builder.html) · [FAQ](https://yurukusa.github.io/cc-safe-setup/faq.html) · [Examples](https://yurukusa.github.io/cc-safe-setup/by-example.html) · [Matrix](https://yurukusa.github.io/cc-safe-setup/matrix.html) · [Playground](https://yurukusa.github.io/cc-hook-registry/playground.html)
|
|
10
10
|
|
|
11
11
|
```bash
|
|
12
12
|
npx cc-safe-setup
|
|
@@ -109,6 +109,21 @@ Each hook exists because a real incident happened without it.
|
|
|
109
109
|
| `--diff-hooks [path]` | Compare hook configurations |
|
|
110
110
|
| `--help` | Show help |
|
|
111
111
|
|
|
112
|
+
## Quick Start by Scenario
|
|
113
|
+
|
|
114
|
+
| I want to... | Command |
|
|
115
|
+
|---|---|
|
|
116
|
+
| Make Claude Code safe right now | `npx cc-safe-setup --shield` |
|
|
117
|
+
| Stop permission prompt spam | `npx cc-safe-setup --install-example auto-approve-readonly` |
|
|
118
|
+
| Enforce a rule instantly | `npx cc-safe-setup --guard "never delete production data"` |
|
|
119
|
+
| See what risks my project has | `npx cc-safe-setup --suggest` |
|
|
120
|
+
| Convert CLAUDE.md rules to hooks | `npx cc-safe-setup --from-claudemd` |
|
|
121
|
+
| Share hooks with my team | `npx cc-safe-setup --team && git add .claude/` |
|
|
122
|
+
| Choose a safety level | `npx cc-safe-setup --profile strict` |
|
|
123
|
+
| See what Claude blocked today | `npx cc-safe-setup --replay` |
|
|
124
|
+
| Know why a hook exists | `npx cc-safe-setup --why destructive-guard` |
|
|
125
|
+
| Migrate from Cursor/Windsurf | [Migration Guide](https://yurukusa.github.io/cc-safe-setup/migration-guide.html) |
|
|
126
|
+
|
|
112
127
|
## How It Works
|
|
113
128
|
|
|
114
129
|
1. Writes hook scripts to `~/.claude/hooks/`
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# ================================================================
|
|
3
|
+
# git-remote-guard.sh — Block push/fetch to unknown git remotes
|
|
4
|
+
# ================================================================
|
|
5
|
+
# PURPOSE:
|
|
6
|
+
# Claude might add a new git remote and push code to it.
|
|
7
|
+
# This hook warns when git push/fetch targets a remote that
|
|
8
|
+
# wasn't in the original repo configuration.
|
|
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
|
+
# Check for git remote add
|
|
17
|
+
if echo "$COMMAND" | grep -qE '\bgit\s+remote\s+add\b'; then
|
|
18
|
+
echo "WARNING: Adding a new git remote." >&2
|
|
19
|
+
echo "Command: $COMMAND" >&2
|
|
20
|
+
echo "Verify this is a trusted repository." >&2
|
|
21
|
+
fi
|
|
22
|
+
|
|
23
|
+
# Check for push to non-origin remote
|
|
24
|
+
if echo "$COMMAND" | grep -qE '\bgit\s+push\s+(?!origin\b)\w'; then
|
|
25
|
+
REMOTE=$(echo "$COMMAND" | grep -oE 'git\s+push\s+(\S+)' | awk '{print $3}')
|
|
26
|
+
if [ -n "$REMOTE" ] && [ "$REMOTE" != "origin" ]; then
|
|
27
|
+
echo "WARNING: Pushing to non-origin remote: $REMOTE" >&2
|
|
28
|
+
echo "Verify this remote is trusted." >&2
|
|
29
|
+
fi
|
|
30
|
+
fi
|
|
31
|
+
|
|
32
|
+
exit 0
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# ================================================================
|
|
3
|
+
# subagent-scope-guard.sh — Limit subagent file access scope
|
|
4
|
+
# ================================================================
|
|
5
|
+
# PURPOSE:
|
|
6
|
+
# In multi-agent setups, subagents should only modify files
|
|
7
|
+
# within their assigned directory. This hook reads a scope
|
|
8
|
+
# file (.claude/agent-scope.txt) and blocks writes outside it.
|
|
9
|
+
#
|
|
10
|
+
# TRIGGER: PreToolUse MATCHER: "Edit|Write"
|
|
11
|
+
#
|
|
12
|
+
# Setup: echo "src/auth/" > .claude/agent-scope.txt
|
|
13
|
+
# ================================================================
|
|
14
|
+
|
|
15
|
+
INPUT=$(cat)
|
|
16
|
+
FILE=$(echo "$INPUT" | jq -r '.tool_input.file_path // empty' 2>/dev/null)
|
|
17
|
+
[ -z "$FILE" ] && exit 0
|
|
18
|
+
|
|
19
|
+
SCOPE_FILE=".claude/agent-scope.txt"
|
|
20
|
+
[ -f "$SCOPE_FILE" ] || exit 0
|
|
21
|
+
|
|
22
|
+
SCOPE=$(cat "$SCOPE_FILE" | head -1 | tr -d '\n')
|
|
23
|
+
[ -z "$SCOPE" ] && exit 0
|
|
24
|
+
|
|
25
|
+
# Check if file is within scope
|
|
26
|
+
case "$FILE" in
|
|
27
|
+
${SCOPE}*) exit 0 ;; # Within scope
|
|
28
|
+
*)
|
|
29
|
+
echo "BLOCKED: File $FILE is outside agent scope ($SCOPE)." >&2
|
|
30
|
+
echo "This agent should only modify files under $SCOPE" >&2
|
|
31
|
+
exit 2
|
|
32
|
+
;;
|
|
33
|
+
esac
|
package/index.mjs
CHANGED
|
@@ -111,6 +111,8 @@ const SAVE_PROFILE = SAVE_PROFILE_IDX !== -1 ? process.argv[SAVE_PROFILE_IDX + 1
|
|
|
111
111
|
const CREATE_IDX = process.argv.findIndex(a => a === '--create');
|
|
112
112
|
const CREATE_DESC = CREATE_IDX !== -1 ? process.argv.slice(CREATE_IDX + 1).join(' ') : null;
|
|
113
113
|
const SUGGEST = process.argv.includes('--suggest');
|
|
114
|
+
const TEST_HOOK_IDX = process.argv.findIndex(a => a === '--test-hook');
|
|
115
|
+
const TEST_HOOK = TEST_HOOK_IDX !== -1 ? process.argv[TEST_HOOK_IDX + 1] : null;
|
|
114
116
|
const WHY_IDX = process.argv.findIndex(a => a === '--why');
|
|
115
117
|
const WHY_HOOK = WHY_IDX !== -1 ? process.argv[WHY_IDX + 1] : null;
|
|
116
118
|
|
|
@@ -144,6 +146,7 @@ if (HELP) {
|
|
|
144
146
|
npx cc-safe-setup --doctor Diagnose why hooks aren't working
|
|
145
147
|
npx cc-safe-setup --watch Live dashboard of blocked commands
|
|
146
148
|
npx cc-safe-setup --create "<desc>" Generate a custom hook from description
|
|
149
|
+
npx cc-safe-setup --test-hook <name> Test a specific hook with sample inputs
|
|
147
150
|
npx cc-safe-setup --save-profile <name> Save current hooks as a named profile
|
|
148
151
|
npx cc-safe-setup --suggest Analyze project and predict risks → suggest hooks
|
|
149
152
|
npx cc-safe-setup --why <hook> Why this hook exists (real incident + issue link)
|
|
@@ -931,6 +934,81 @@ async function fullSetup() {
|
|
|
931
934
|
console.log();
|
|
932
935
|
}
|
|
933
936
|
|
|
937
|
+
async function testHook(hookName) {
|
|
938
|
+
const { execSync } = await import('child_process');
|
|
939
|
+
console.log();
|
|
940
|
+
|
|
941
|
+
if (!hookName) {
|
|
942
|
+
console.log(c.bold + ' cc-safe-setup --test-hook <name>' + c.reset);
|
|
943
|
+
console.log(c.dim + ' Test any hook with sample inputs.' + c.reset);
|
|
944
|
+
console.log();
|
|
945
|
+
console.log(' Example: npx cc-safe-setup --test-hook destructive-guard');
|
|
946
|
+
return;
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
const name = hookName.replace('.sh', '');
|
|
950
|
+
// Find the hook
|
|
951
|
+
let hookPath = join(HOOKS_DIR, `${name}.sh`);
|
|
952
|
+
if (!existsSync(hookPath)) hookPath = join(__dirname, 'examples', `${name}.sh`);
|
|
953
|
+
if (!existsSync(hookPath)) {
|
|
954
|
+
console.log(c.red + ` Hook "${name}" not found.` + c.reset);
|
|
955
|
+
return;
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
console.log(c.bold + ` Testing: ${name}` + c.reset);
|
|
959
|
+
console.log(c.dim + ` File: ${hookPath}` + c.reset);
|
|
960
|
+
console.log();
|
|
961
|
+
|
|
962
|
+
// Sample inputs per hook type
|
|
963
|
+
const SAMPLES = {
|
|
964
|
+
'should-block': [
|
|
965
|
+
{ desc: 'dangerous rm', input: '{"tool_input":{"command":"rm -rf /"}}' },
|
|
966
|
+
{ desc: 'git reset hard', input: '{"tool_input":{"command":"git reset --hard"}}' },
|
|
967
|
+
{ desc: 'force push', input: '{"tool_input":{"command":"git push origin main --force"}}' },
|
|
968
|
+
{ desc: 'git add .env', input: '{"tool_input":{"command":"git add .env"}}' },
|
|
969
|
+
{ desc: 'sudo command', input: '{"tool_input":{"command":"sudo rm -rf /home"}}' },
|
|
970
|
+
{ desc: 'drop database', input: '{"tool_input":{"command":"DROP DATABASE production"}}' },
|
|
971
|
+
],
|
|
972
|
+
'should-allow': [
|
|
973
|
+
{ desc: 'safe ls', input: '{"tool_input":{"command":"ls -la"}}' },
|
|
974
|
+
{ desc: 'git status', input: '{"tool_input":{"command":"git status"}}' },
|
|
975
|
+
{ desc: 'npm test', input: '{"tool_input":{"command":"npm test"}}' },
|
|
976
|
+
{ desc: 'cat file', input: '{"tool_input":{"command":"cat README.md"}}' },
|
|
977
|
+
{ desc: 'empty input', input: '{}' },
|
|
978
|
+
],
|
|
979
|
+
};
|
|
980
|
+
|
|
981
|
+
let pass = 0, total = 0;
|
|
982
|
+
|
|
983
|
+
for (const [category, samples] of Object.entries(SAMPLES)) {
|
|
984
|
+
console.log(c.dim + ` ${category}:` + c.reset);
|
|
985
|
+
for (const sample of samples) {
|
|
986
|
+
total++;
|
|
987
|
+
try {
|
|
988
|
+
execSync(`echo '${sample.input}' | bash "${hookPath}"`, { stdio: 'pipe', timeout: 5000 });
|
|
989
|
+
// Exit 0 = allowed
|
|
990
|
+
const icon = category === 'should-allow' ? c.green + '✓' : c.yellow + '·';
|
|
991
|
+
console.log(` ${icon}${c.reset} ${sample.desc} → allowed (exit 0)`);
|
|
992
|
+
if (category === 'should-allow') pass++;
|
|
993
|
+
} catch (e) {
|
|
994
|
+
const code = e.status;
|
|
995
|
+
if (code === 2) {
|
|
996
|
+
// Blocked
|
|
997
|
+
const icon = category === 'should-block' ? c.green + '✓' : c.red + '✗';
|
|
998
|
+
console.log(` ${icon}${c.reset} ${sample.desc} → ${c.red}BLOCKED${c.reset} (exit 2)`);
|
|
999
|
+
if (category === 'should-block') pass++;
|
|
1000
|
+
} else {
|
|
1001
|
+
console.log(` ${c.yellow}?${c.reset} ${sample.desc} → exit ${code}`);
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
console.log();
|
|
1008
|
+
console.log(` ${pass}/${total} samples matched expected behavior`);
|
|
1009
|
+
console.log();
|
|
1010
|
+
}
|
|
1011
|
+
|
|
934
1012
|
async function saveProfile(name) {
|
|
935
1013
|
const { readdirSync } = await import('fs');
|
|
936
1014
|
const profilesDir = join(HOME, '.claude', 'profiles');
|
|
@@ -4340,6 +4418,7 @@ async function main() {
|
|
|
4340
4418
|
if (FULL) return fullSetup();
|
|
4341
4419
|
if (DOCTOR) return doctor();
|
|
4342
4420
|
if (WATCH) return watch();
|
|
4421
|
+
if (TEST_HOOK_IDX !== -1) return testHook(TEST_HOOK);
|
|
4343
4422
|
if (SAVE_PROFILE_IDX !== -1) return saveProfile(SAVE_PROFILE);
|
|
4344
4423
|
if (SUGGEST) return suggest();
|
|
4345
4424
|
if (WHY_IDX !== -1) return why(WHY_HOOK);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cc-safe-setup",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.1.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": {
|