← ai-atoms

Hooks (13)

Event-driven behaviors wired into AI tool infrastructure. Each hook declares the event it responds to (e.g. PreToolUse, SessionStart), its trigger pattern, the script language, and whether it blocks execution.

1Password & Secret Redactor

non-blocking stable

PreToolUse hook that redacts 1Password references and secret-shaped values from Claude Code tool-use payloads before they execute. Unlike secret-block which denies, this hook redacts in-place and always exits 0 — it never blocks the tool call. Patterns: GitHub tokens (gho_/ghp_/ghu_/ghs_/ghr_), Bearer tokens, op:// references, OpenAI sk- keys, PEM blocks. Writes a violation record on detection. Implements Common.md §4 (non-overridable secret handling).

Event PreToolUse Language python Trigger always Side effects
  • redacts secrets in-place in tool payload
  • writes violation record to ~/.ai/audit/violations/<UTC>-secret-detected.md
  • outputs cleaned JSON to stdout
linuxmacoswindows invoke via ai hooks run op-redact

Logic is cross-platform. Wiring: use 'ai hooks run op-redact' in settings.json — the ai binary discovers Python on each OS. Pure Python regex; no OS-specific calls. Works on all platforms.

securitysecretsredaction1passwordgovernanceclaude-code
hook/op-redact · v1.0.0

Audit Command Wrapper

non-blocking stable

PostToolUse hook that records every wrapped command invocation (git, gh, etc.) to the audit log. Makes the appearance side of the audit trail reliable — absence of an audit line for an expected command is itself visible during forensic review. Records WRAPPED_CMD, WRAPPED_ARGV, WRAPPED_EXIT, and WRAPPED_DURATION.

Event PostToolUse Language python Trigger always Side effects
  • appends invocation record to ~/.ai/audit/interactions/<YYYY-MM>.jsonl
linuxmacoswindows invoke via ai hooks run audit-command

Logic is cross-platform. Wiring: use 'ai hooks run audit-command' in settings.json — the ai binary discovers Python on each OS. Reads env vars WRAPPED_CMD etc. — set by the ai command wrappers on all platforms.

auditlogginggovernancecommandsclaude-code
hook/audit-command · v1.0.0

Branch Guard

blocking stable

Prevents direct mutations to protected branches (main, release/*). Intercepts git commit, merge, rebase, cherry-pick, revert, am, pull, and push operations when the current HEAD is a protected branch. Requires explicit approval per Common.md §2.2.

Event PreToolUse Language python Trigger tool-name Bash Side effects
  • blocks tool call with explanation
  • emits protected-branch warning
linuxmacoswindows invoke via ai hooks run branch-guard

Logic is cross-platform. Wiring: use 'ai hooks run branch-guard' in settings.json — the ai binary discovers Python on each OS. Inspects git command strings — git works cross-platform. Python shebang ignored on Windows; invoked via 'ai hooks run'.

gitgovernancebranch-protectionclaude-code
hook/branch-guard · v1.0.0

Checkpoint Tick

non-blocking stable

30-minute background tick that writes a HANDOFF.md so context-window resets don't lose state. Implements Common.md §U10 (handoff + checkpoint) and §U13 (context-window discipline). If more than 30 minutes have elapsed since the last tick, invokes the /checkpoint skill or emits a minimal HANDOFF.md template at cwd. Updates the timestamp on every run.

Event Stop Language python Trigger always Side effects
  • writes HANDOFF.md at cwd
  • updates ~/.config/aiConstitution/checkpoints/<project>/.last-tick
linuxmacoswindows invoke via ai hooks run checkpoint-tick

Logic is cross-platform. Wiring: use 'ai hooks run checkpoint-tick' in settings.json — the ai binary discovers Python on each OS. Already contains sys.platform == 'win32' logic for config dir (%APPDATA%\aiConstitution on Windows).

checkpointhandoffcontext-windowcontinuityclaude-code
hook/checkpoint-tick · v1.0.0

Destructive GitHub CLI Guard

blocking stable

Blocks high-blast-radius, irreversible gh CLI operations per Common.md §2.2. Denies without explicit --force-i-mean-it confirmation: gh repo delete, gh release delete, gh secret delete, and gh auth logout. All other gh subcommands pass through.

Event PreToolUse Language python Trigger tool-name Bash Side effects
  • blocks tool call with explanation and bypass instructions
linuxmacoswindows invoke via ai hooks run destructive-gh-guard

Logic is cross-platform. Wiring: use 'ai hooks run destructive-gh-guard' in settings.json — the ai binary discovers Python on each OS. gh CLI available on all platforms. Python logic is cross-platform.

governancegh-clidestructiveguardclaude-code
hook/destructive-gh-guard · v1.0.0

Destructive kubectl Guard

blocking stable

Blocks destructive kubectl operations per Common.md §2.2. Opt-in via command-wrappers.toml. Denies kubectl delete, kubectl drain, and kubectl cordon without the bypass env AI_ALLOW_DESTRUCTIVE_KUBECTL=1. All other kubectl subcommands pass through.

Event PreToolUse Language python Trigger tool-name Bash Side effects
  • blocks tool call with explanation
  • bypass via AI_ALLOW_DESTRUCTIVE_KUBECTL=1
linuxmacoswindows invoke via ai hooks run destructive-kubectl-guard

Logic is cross-platform. Wiring: use 'ai hooks run destructive-kubectl-guard' in settings.json — the ai binary discovers Python on each OS. kubectl available on all platforms. Python logic is cross-platform.

governancekubectlkubernetesdestructiveguardclaude-code
hook/destructive-kubectl-guard · v1.0.0

Destructive Terraform Guard

blocking stable

Blocks terraform destroy and terraform apply per Common.md §2.2. Opt-in via command-wrappers.toml. Requires explicit bypass via AI_ALLOW_DESTRUCTIVE_TERRAFORM=1. Prevents accidental infrastructure destruction or unreviewed applies. Other tofu/terraform subcommands (plan, init, validate, output) pass through.

Event PreToolUse Language python Trigger tool-name Bash Side effects
  • blocks tool call with explanation
  • bypass via AI_ALLOW_DESTRUCTIVE_TERRAFORM=1
linuxmacoswindows invoke via ai hooks run destructive-terraform-guard

Logic is cross-platform. Wiring: use 'ai hooks run destructive-terraform-guard' in settings.json — the ai binary discovers Python on each OS. tofu/terraform available on all platforms. Python logic is cross-platform.

governanceterraformtofuinfrastructuredestructiveguardclaude-code
hook/destructive-terraform-guard · v1.0.0

GitHub Actions Security Reminder

non-blocking stable

Fires when Claude Code edits a GitHub Actions workflow file. Non-blocking reminder about command injection risks, untrusted input in run: steps, and the SAFE pattern (env: with proper quoting vs direct ${{ expression }} interpolation).

Event PreToolUse Language python Trigger file-pattern .github/workflows/*.yml Side effects
  • emits security guidance to stderr
linuxmacoswindows invoke via ai hooks run security-reminder

Logic is cross-platform. Wiring: use 'ai hooks run security-reminder' in settings.json — the ai binary discovers Python on each OS. Pure Python; writes to stderr. Works on all platforms.

securitygithub-actionsciclaude-code
hook/security-reminder · v1.0.0

Interaction Audit Logger

non-blocking stable

Appends a JSONL record to ~/.ai/audit/interactions/<YYYY-MM>.jsonl for every Claude Code hook event: SessionStart, UserPromptSubmit, PreToolUse, PostToolUse, Stop, SessionEnd, SubagentStop, PreCompact. Non-blocking. Implements Common.md §5.2.

Event PreToolUse Language python Trigger always Side effects
  • writes to ~/.ai/audit/interactions/<YYYY-MM>.jsonl
linuxmacoswindows invoke via ai hooks run audit-logger

Logic is cross-platform. Wiring: use 'ai hooks run audit-logger' in settings.json — the ai binary discovers Python on each OS. Writes to ~/.ai/audit/ — path resolves correctly cross-platform via Python pathlib.

auditlogginggovernanceclaude-code
hook/audit-logger · v1.0.0

No-Verify Strip

non-blocking stable

PreToolUse hook that strips --no-verify from git commit commands before they execute. Per Common.md §2.2 (no skipping hooks) and the governance SPEC §10.3. Default behavior: strip silently and log the bypass attempt to the audit pipeline. The bypass can be allowed per-project via allowNoVerifyBypass=true in settings, which removes this hook from the preHooks list.

Event PreToolUse Language python Trigger tool-name Bash Side effects
  • removes --no-verify flag from git commit argv
  • logs bypass attempt to audit pipeline
linuxmacoswindows invoke via ai hooks run no-verify-strip

Logic is cross-platform. Wiring: use 'ai hooks run no-verify-strip' in settings.json — the ai binary discovers Python on each OS. Modifies git argv in-process — cross-platform. Invoked via 'ai hooks run'.

gitgovernancehooksauditno-verifyclaude-code
hook/no-verify-strip · v1.0.0

Secret Block

blocking stable

PreToolUse hook that denies Bash commands containing secret-shaped strings before they execute. Reads the canonical pattern set from hooks/patterns.json (plus patterns.local.json if present). Belt-and-suspenders alongside the secret-handling rules in Common.md §4. Emits a JSON permissionDecision deny on detection.

Event PreToolUse Language python Trigger tool-name Bash Side effects
  • denies tool call with explanation when secret pattern detected
linuxmacoswindows invoke via ai hooks run secret-block

Logic is cross-platform. Wiring: use 'ai hooks run secret-block' in settings.json — the ai binary discovers Python on each OS. Pure Python regex on stdin JSON. Works on all platforms.

securitysecretsgovernancepatternsclaude-code
hook/secret-block · v1.0.0

Secret Pre-commit Scanner

blocking stable

Git pre-commit hook and CI scanner that blocks commits containing secret-shaped strings. Two modes: (1) pre-commit — scans the staged diff (git diff --cached -U0) and aborts the commit on any match; (2) CI/range scan (--ci --base BASE --head HEAD) — scans the diff from BASE..HEAD for use in secret-scan.yml workflows. Reads canonical patterns from hooks/patterns.json.

Event PreToolUse Language python Trigger tool-name Bash Side effects
  • aborts git commit on secret detection
  • exits non-zero in CI scan mode on detection
linuxmacoswindows invoke via ai hooks run secret-precommit

Logic is cross-platform. Wiring: use 'ai hooks run secret-precommit' in settings.json — the ai binary discovers Python on each OS. Calls subprocess git diff — git is available cross-platform. Pre-commit mode uses 'exec python3' in the shim; Windows users should use 'ai hooks run' instead.

securitysecretsgitpre-commitciclaude-code
hook/secret-precommit · v1.0.0

Worktree Placement Guard

blocking stable

Enforces canonical git worktree placement per Common.md §U17. Denies 'git worktree add' commands that target ad-hoc paths (../branch/, /tmp/, sibling dirs). Canonical paths: <repo>/.worktrees/<name>/ for single-repo work, ~/.ai/worktrees/<name>/ for cross-repo or persistent worktrees.

Event PreToolUse Language python Trigger tool-name Bash Side effects
  • blocks non-canonical worktree creation with path guidance
linuxmacoswindows invoke via ai hooks run worktree-guard

Logic is cross-platform. Wiring: use 'ai hooks run worktree-guard' in settings.json — the ai binary discovers Python on each OS. Inspects git command strings via Python. Path separators handled by pathlib. Works on all platforms.

gitworktreegovernanceclaude-code
hook/worktree-guard · v1.0.0