Destructive-command check stops asking about scratch deletes and blocks real damage (GST-3169) (#4513)

The destructive-command check no longer asks before deleting temp, cache
or build folders, and now catches dangerous commands it used to miss:
deletes outside the project, force-pushes to main inside longer
commands, history rewrites, database resets and cloud deletes.

Agents were stopped for harmless cleanup while real damage got through:
on a 102-row replay of real command shapes, main gives the expected
answer on 66 and this branch on all 102.

Nothing to do, except: an Agent SDK app where a person answers prompts
should set `GSTACK_SESSION_KIND=interactive`.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Review-Finding: p1/specialist-batched#1 reader=security
Review-Finding: p1/specialist-batched#2 reader=security
Review-Finding: p1/red-team#1 reader=red-team
Review-Finding: p1/red-team#2 reader=red-team
Review-Finding: p1/red-team#3 reader=red-team
Review-Finding: p1/red-team#4 reader=red-team
Review-Finding: p1/red-team#5 reader=red-team
Review-Finding: p2/red-team#1 reader=red-team
This commit is contained in:
Garry Tanandcapy-ai[bot] authored and GitHub committed 2026-11-19 10:40:49 +00:00
1 parent 957fab79c5
commit 55aaa6c4a5
16 files changed
+1203 -297

No files matched your search

+3 -1
View File
@@ -74,7 +74,9 @@ Every decision is one line in `$GSTACK_STATE_ROOT/hooks/skill-route.log`: the se
<a id="destructive-command-check"></a>
## Destructive-command check
`./setup` registers `hosts/claude/hooks/destructive-guard-hook` as a PreToolUse hook on `Bash|PowerShell`. It runs `careful/bin/check-careful.sh`, the same check /careful and /guard load, so it fires even when the model never loads /careful. Its decisions are the check's own: `ask` before the destructive families (`rm -rf`, `DROP TABLE`, `TRUNCATE`, force-push, `git reset --hard`, `kubectl delete` and the rest in /careful's table), which you can always approve, and `deny` for the two catastrophic simple shapes (a recursive delete of `/` or your home directory, and a force-push to the default branch). An ask's reason, which you read, adds `(gstack's destructive-command check, on in every session; off: gstack-config set destructive_guard off)`; a deny's reason, which the model reads, never names the off switch. In a session nobody is watching (`claude -p`, which Claude Code marks `CLAUDE_CODE_ENTRYPOINT=sdk-cli`, or a session `gstack-session-kind` reports as headless), an ask would wait for an answer that never comes, so the hook prints the same reason as a warning and lets the command run, which is what happens when the check is off; a deny stays a deny. It costs about a tenth of a second per Bash call.
`./setup` registers `hosts/claude/hooks/destructive-guard-hook` as a PreToolUse hook on `Bash|PowerShell`. It runs `careful/bin/check-careful.sh`, the same check /careful and /guard load, so it fires even when the model never loads /careful. Its decisions are the check's own: `ask` before the destructive families (`rm -rf`, `DROP TABLE`, `TRUNCATE`, force-push, `git reset --hard`, `kubectl delete` and the rest in /careful's table), which you can always approve, and `deny` for three catastrophic shapes in any command shape (a recursive delete of `/`, your home directory or a system or personal folder; a force-push to `main`, `master` or the default branch; a raw write or wipe of a whole disk). An ask's reason, which you read, adds `(gstack's destructive-command check, on in every session; off: gstack-config set destructive_guard off)`; a deny's reason, which the model reads, never names the off switch. In a session nobody is watching (`claude -p`, which Claude Code marks `CLAUDE_CODE_ENTRYPOINT=sdk-cli`; an Agent SDK program, marked `sdk-py` or `sdk-ts`; or a session `gstack-session-kind` reports as headless), an ask would wait for an answer that never comes, so the hook prints the same reason as a warning and lets the command run, which is what happens when the check is off; a deny stays a deny. It costs about a tenth of a second per Bash call.
In an Agent SDK program an ask with no permission callback is denied outright (checked with a real SDK run), which is why SDK sessions get the warning. An SDK host where a person does answer asks, through a permission callback, should set `GSTACK_SESSION_KIND=interactive` to keep them; Conductor is recognized on its own. A harness that drives Claude Code some other way with nobody to answer (a CI job, an eval runner) should set `GSTACK_SESSION_KIND=unattended`, so the hook turns its asks into warnings the same way.
The hook reads `destructive_guard` every time it runs, so `gstack-config set destructive_guard off` takes effect on the next command. With it off, /careful and /guard still load their own session hooks.
+9 -7
View File
@@ -1492,19 +1492,21 @@ Four skills that add safety rails to any Claude Code session. They work via Clau
Say "be careful" or run `/careful` when you're working near production, running destructive commands, or just want a safety net. Every Bash and PowerShell command gets checked against known-dangerous patterns:
- `rm -rf` / `rm -r` — recursive delete
- `DROP TABLE` / `DROP DATABASE` / `TRUNCATE` — data loss
- `git push --force` / `git push -f` — history rewrite
- `git reset --hard` — discard commits
- `git checkout .` / `git restore .` — discard uncommitted work
- `rm -rf` / `rm -r` of anything that isn't scratch — recursive delete
- `rm`, `find -delete`, `rsync --delete`, `shred` or `unlink` outside the session folder, or through a variable that may be unset — files git can't bring back
- SQL `DROP TABLE` / `DROP DATABASE` / `TRUNCATE` run by a database client — data loss
- `git push --force` / `-f` / `+ref` / `--force-with-lease` and remote branch deletes — history rewrite
- `git reset --hard`, `checkout -- paths`, `checkout -f`, `switch -f`, `restore`, `clean -f` — only when the tree really has uncommitted work they would discard; `stash drop` and `worktree remove --force` always
- `filter-branch`, `filter-repo`, BFG, `reflog expire --expire=now`, `gc --prune=now` — history you can't get back
- database resets (`prisma migrate reset`, `supabase db reset`, `rails db:drop`, `dropdb`, `FLUSHALL`) and cloud deletes (`terraform destroy`, `aws` delete calls, `helm uninstall`, `gh repo delete`, `docker volume rm`)
- `kubectl delete` — production resource deletion
- `docker rm -f` / `docker system prune` — container/image loss
On Windows the same hook checks Claude Code's PowerShell tool and any `pwsh`/`powershell`/`cmd` launched from Bash: `Remove-Item` and its aliases with `-Recurse`/`-Force` (any parameter prefix), cmd `rd /s` and `del /s`, `Format-Volume`, `Clear-Disk`, `Clear-Content` and .NET deletes ask, and encoded or dynamic PowerShell (`-EncodedCommand`, `iex`, `Start-Process` of a shell, `& $cmd`) asks because it can't be inspected. PowerShell coverage is best-effort; Claude Code permission deny rules such as `"PowerShell(Remove-Item *)"` are the hard stop.
Common build artifact cleanups (`rm -rf node_modules`, `dist`, `.next`, `__pycache__`, `build`, `coverage`) are whitelisted — no false alarms on routine operations.
Deleting scratch never asks: anything under `/tmp/` or `/var/tmp/`, a `mktemp` folder, caches such as `~/.cache` and `~/.npm`, and build output (`node_modules`, `dist`, `.next`, `__pycache__`, `build`, `coverage`, `.venv`, `.pytest_cache` and the like). In a replay of 254,322 agent commands, `/tmp` deletes were 95% of the old check's false asks.
You can override any MEDIUM warning. Two catastrophic shapes are hard-denied instead of asked: recursive deletes of the filesystem root or your home directory (including the `/*`, `~/`, and `$HOME/` forms), and force-pushes to the repo's default branch (`--force-with-lease` never triggers the deny; to run one anyway, turn the every-session check off with `gstack-config set destructive_guard off` and don't load `/careful` or `/guard`). You can also add your own warn rules — one POSIX ERE per line — in `~/.gstack/careful-patterns.txt` (global) or `~/.gstack/projects/<slug>/careful-patterns.txt` (per-project); custom patterns only ever add warnings, never suppress the built-ins. The guardrails are accident prevention, not access control.
You can override any MEDIUM warning. Three catastrophic shapes are hard-denied instead of asked, however the command is written: recursive deletes of the filesystem root, your home directory, a top-level system folder or a personal folder such as `~/.ssh` or `~/Documents`; force-pushes to `main`, `master` or the repo's default branch (`--force-with-lease` alone never triggers the deny); and raw writes, formats or wipes of a whole disk (to run one anyway, turn the every-session check off with `gstack-config set destructive_guard off` and don't load `/careful` or `/guard`). You can also add your own warn rules — one POSIX ERE per line — in `~/.gstack/careful-patterns.txt` (global) or `~/.gstack/projects/<slug>/careful-patterns.txt` (per-project); custom patterns only ever add warnings, never suppress the built-ins. The guardrails are accident prevention, not access control.
### `/freeze`