Skip to content

Business operating system for Claude Code — 57 skills, 21 agents, smart daemon. Unified inbox (WhatsApp/Email/Slack/Telegram), autonomous PR merge, full-AWS monitoring, revenue (Stripe+RevenueCat), e-commerce (Shopify), marketing (Klaviyo/Meta/GA4), voice (Bland/ElevenLabs), APM (Datadog/NewRelic/OTEL), YOLO mode.

7.1 KB
Raw Blame

Universal Safety Hooks

Three PreToolUse:Bash hooks that block the most common foot-guns: secrets in commits, rm -rf against anchor paths, and direct git push to main.

version hook always-on


Why these are not gated by userConfig

The other v2 subsystems (deploy-fix, recap, rotator, task-reminder) are toggleable from /plugins settings because they're additive convenience layers. The three safety hooks are different — they prevent irrecoverable damage (committed secrets, deleted home directories, broken main branches). They're always-on by design, with a per-incident escape via Claude Code's standard permissionDecision flow.

If you genuinely need to disable one, comment out the entry in hooks/hooks.json. There is no shame in this — but make it a deliberate choice, not a forgotten toggle.


The three hooks

1. bin/ops-prevent-secret-commit

Trigger: PreToolUse:Bash matching git commit *.

Action: Scans git diff --cached for known secret patterns. On match, returns permissionDecision: deny with an explanation listing the matched pattern + offending file.

Patterns detected:

Pattern Match
AWS access key AKIA[0-9A-Z]{16}
AWS secret key aws_secret_access_key\s*=\s*["']?[A-Za-z0-9/+=]{40}
GitHub PAT ghp_[A-Za-z0-9]{36} / github_pat_[A-Za-z0-9_]{82}
Slack token xox[baprs]-[A-Za-z0-9-]{10,}
OpenAI API key sk-(proj-)?[A-Za-z0-9]{20,}
Anthropic API key sk-ant-[A-Za-z0-9_-]{20,}
Stripe live key sk_live_[A-Za-z0-9]{24,}
.env content any staged .env* file (excluding .env.example, .env.template)
Generic high-entropy string any 32+ char base64-ish run with KEY / TOKEN / SECRET in the variable name

Override: un-stage the offending file (git restore --staged <path>), or scrub the value. There's no env-var override; this is intentional.


2. bin/ops-no-rm-rf-anchor

Trigger: PreToolUse:Bash matching rm -rf * (and equivalents: rm -fr, rm -rfv, etc.).

Action: Resolves each target via realpath/readlink -f (so symlinks don't sneak past). On any of these resolved targets, returns permissionDecision: deny:

  • /
  • $HOME / ~ (and any path that resolves to $HOME)
  • .. and . (when CWD itself is $HOME or /)
  • Mount points listed in /etc/fstab (root-level only)

Override: there is none for the listed anchors. If you genuinely need to wipe ~, do it outside Claude Code.


3. bin/ops-warn-mainpush

Trigger: PreToolUse:Bash matching git push *.

Action: Reads the current branch via git rev-parse --abbrev-ref HEAD. If the branch is in the protected list (main, master, prod, production, release), returns permissionDecision: ask (not deny — ask) with the message:

About to push directly to <branch>. This bypasses the PR review flow.
Confirm by accepting the prompt; abort by rejecting.

Override: accept the standard Claude Code permission prompt. No env-var or config override.

This hook intentionally uses ask not deny because force-push to main is sometimes legitimate (recovering from a broken merge, hotfix, etc.) — but it should never be silent.


How permissionDecision works

Claude Code's standard PreToolUse mechanism supports three decisions:

  • allow — pass through silently.
  • ask — prompt the user; user accepts → pass through.
  • deny — block the call, return the explanation to Claude.

The three safety hooks use this mechanism. They never modify the command or rewrite arguments; they only inspect and decide.


Disabling a single hook

Edit hooks/hooks.json and remove the relevant entry under PreToolUse > Bash. Reload the plugin (/plugin reload ops) for the change to take effect.

To re-enable, copy the entry back from the v2 release notes or the GitHub source.


Testing

tests/test-safety-hooks.sh covers every hook with positive (should-deny / should-ask) and negative (should-allow) cases. 45/45 pass on macOS + Linux.

Run locally:

bash claude-ops/tests/test-safety-hooks.sh

See also

bedrock-billing-guard (PreToolUse) — metered-spend protection

hooks/bedrock-billing-guard.mjs hard-stops any Claude session that is measured to be billing AWS Bedrock (metered per-token spend, not the Max OAuth account pool). It is the agent-facing complement to the rotation daemon's scripts/account-rotation/bedrock-watchdog.mjs, which detects + force-swaps such sessions off Bedrock within ~45s.

How it knows. A PreToolUse hook runs as a child of the session's node process, so it inherits the live process.env — including a runtime-injected CLAUDE_CODE_USE_BEDROCK=1 (the literal billing flag). That env var is the measurement; there is no false positive. It also honors a daemon-written offender flag (/tmp/claude-bedrock-offender-<short-session-id>) from the watchdog's network/env measurement.

Behavior — configurable via CLAUDE_BEDROCK_GUARD (or ~/.claude/bedrock-guard.conf):

mode effect
block (default) Hard-block every tool call (exit 2) with a loud $$$ error. Dismiss only by explicit acknowledgement: run echo BEDROCK-ACK. This is the only way to proceed while still on Bedrock (the legitimate no-OAuth last-resort case).
warn Never block — inject a one-line non-blocking warning into the agent's context on each tool call.
off No-op. For users who intentionally run Bedrock unrestricted.

When OAuth headroom exists, the watchdog respawns the session onto OAuth and clears the flag, so the block lifts on its own. The guard is fail-open: any error, missing input, or unexpected state allows the tool (a money guard must never wedge an innocent session).

Disable / make unrestricted: set CLAUDE_BEDROCK_GUARD=off in the environment, or echo off > ~/.claude/bedrock-guard.conf.