Gemini CLI Hooks Pack: 10 Ready Hooks + Linter + Simulator

Stop Gemini CLI from force-pushing main or editing your .env, and make it run the tests before it says it's done.

Gemini CLI Hooks Pack: 10 Ready Hooks + Linter + Simulator product illustration

What it does

10 tested hooks for Google's Gemini CLI, plus an installer that merges them into .gemini/settings.json, a simulator that runs any hook the way Gemini CLI does and checks its output contract, and a linter that catches the mistakes that make hooks silently never fire. Python 3.9+, standard library only, works offline. Linux, macOS, WSL.

What you get

The screenshot is real output from the kit’s own commands. Tested from a fresh download of this exact zip: ./run_tests.sh ran 24 tests OK on Python 3.13 and 3.10.

Real terminal output from Gemini CLI Hooks Pack: 10 Ready Hooks + Linter + Simulator: demo and passing tests

The hooks

Hook (name in settings.json)Event / matcherWhat it does
block-dangerous-shellBeforeTool run_shell_commandDenies rm -rf / ~ *, force push / +branch to protected branches, git reset --hard, git clean -fdx, curl | sh, chmod -R 777, mkfs, dd of=/dev/..., DROP DATABASE, terraform destroy, kubectl delete namespace. rm -rf node_modules and feature-branch force pushes stay allowed.
protect-filesBeforeTool write_file|replace|run_shell_commandBlocks edits to .env*, keys/certs, secrets/, .git/ and the hook config itself, including shell writes (>>, sed -i, cp, tee, rm). .env.example stays editable.
mcp-guardBeforeTool mcp_.*Allow/deny lists for MCP tools (mcp_<server>_<tool> globs) and blocks MCP calls whose arguments contain secrets.
scan-prompt-secretsBeforeAgentStops a prompt that contains an API key/token before it reaches the model, without echoing the secret back.
redact-tool-outputAfterTool (file, shell, web, MCP tools)Replaces secrets in tool output with a redaction placeholder before the model sees them.
session-contextSessionStartAdds branch, changed files, recent commits and your .gemini/notes.md as context (capped at 4,000 chars).
require-testsAfterAgentWhen code changed, runs your test command; on failure it sends the failing output back so Gemini fixes it. Skips doc-only changes and never loops (stop_hook_active).
precompress-notesPreCompressAppends branch/changed files to .gemini/notes.md before context compression.
audit-logAfterTool *JSONL log of every tool call (secrets redacted) in .gemini/logs/audit.jsonl.
notifyNotification ToolPermissionDesktop notification (notify-send / osascript) when Gemini waits for approval, plus a JSONL log.

Profiles: balanced (default, first 7), strict (all 10), guardrails (first 5, no lifecycle hooks), logging (audit, context, notes, notify). Ready-made templates/settings.<profile>.json are included if you prefer to copy by hand.

Install

python3 tools/install.py /path/to/repo                       # balanced profile into .gemini/settings.json
python3 tools/install.py /path/to/repo --profile strict
python3 tools/install.py /path/to/repo --only block-dangerous-shell,protect-files
python3 tools/install.py --user --profile guardrails          # ~/.gemini for every project
python3 tools/install.py /path/to/repo --dry-run              # show the merged settings.json, change nothing

The installer copies the scripts to .gemini/hooks/, merges hooks by name (your own hooks and other settings are kept, re-running is safe), writes settings.json.bak, and never overwrites an edited hooks-config.json. Gemini CLI fingerprints project hooks: on the next start it warns you about the new hooks; review them, then check /hooks panel. Turn one off with /hooks disable <name> or add the name to hooks.disabled.

Configure

Edit .gemini/hooks/hooks-config.json: protected_paths, protected_branches, mcp_allow / mcp_deny, test_command (empty = auto-detect npm test, pytest or unittest, go test ./..., cargo test), test_timeout, context_limit_chars, log paths, desktop_notifications.

Test a hook without Gemini CLI

python3 tools/simulate.py hooks/block_dangerous_shell.py BeforeTool --tool run_shell_command --command "git push -f origin main"
python3 tools/simulate.py my_hook.py AfterAgent --prompt "fix it" --stop-hook-active
python3 tools/simulate.py my_hook.py BeforeTool --event event.json --json

It prints the decision Gemini CLI would take and flags contract problems: text before the JSON on stdout (Gemini then ignores your deny and shows the text as a message), deny without a reason, decisions on advisory events, exit codes that only warn.

Lint settings.json

python3 tools/gemini_hooks_lint.py .gemini/settings.json ~/.gemini/settings.json   # exit 1 on errors, --json available

Checks: unknown events (Claude Code names like PreToolUse), Claude tool names (Bash, Write) and mcp__server__tool matchers, invalid regexes, regex matchers on lifecycle events (they are exact strings), bad SessionStart / PreCompress values, missing hooks arrays, type other than command, timeouts given in seconds (Gemini uses milliseconds), duplicate names, relative script paths, missing scripts, secrets in commands, and stale hooks.disabled entries.

60-second demo

./tools/demo.sh      # simulate hooks, lint examples/broken, install into a temp repo and lint it
./run_tests.sh       # 24 unit tests, offline

docs/events.md is a one-page reference of all 11 events, their matchers and what each output field does.

Honest limits

  • Pattern-based guards reduce risk; they are not a sandbox. Keep Gemini CLI's own approval mode and sandboxing on.
  • Built against Gemini CLI's hooks documentation as of November 2026. If Google changes the hook contract, re-run the linter and simulator.
  • require-tests runs your test suite after each agent turn that changed code; set test_command to something fast.
  • Not affiliated with Google. "Gemini" is a trademark of Google LLC.

Format and license

Zip, 40 KB, v1.0, 32 files. You may use and modify this kit for your own work and for clients you serve, including paid client work. Not affiliated with or endorsed by Google.

FAQ

Where do the hooks go?
Into .gemini/settings.json in your project (or ~/.gemini with --user). The installer merges them by name and keeps your other settings and hooks.
Will it block my normal work?
The rules target clearly destructive commands; rm -rf node_modules, force pushes to feature branches and git reset --soft pass. Every list is editable in hooks-config.json.
Can I check hooks I already have?
Yes: python3 tools/gemini_hooks_lint.py .gemini/settings.json. It exits 1 on errors, so it fits CI.
How do I get the files?
Pay by card right here on youraitools.co: your download links appear on this page the moment the payment goes through (claim window: 72 hours, up to 5 downloads per 7 days). Need the files re-sent later? Email hello@youraitools.co.
Refunds?
Email hello@youraitools.co within 14 days if it doesn’t work and we can’t fix it.
Can I pay with crypto?
Yes. Pay the same price in USDC or USDT on Base, Ethereum, Arbitrum, Optimism, Polygon or Solana from the "Pay with crypto" button, with no account or KYC. We check the payment on-chain and show your download links as soon as it confirms.

Get Gemini CLI Hooks Pack: 10 Ready Hooks + Linter + Simulator

10 ready Gemini CLI hooks: block rm -rf and force pushes, protect .env, redact secrets, run tests after each turn, plus a hooks linter and simulator.

Pairs well with

Download$119

Agent Builder Bundle

Swarm Operator Kit + x402 Builder Skills + MCP Starter Kit. $119 instead of $157.

View Agent Builder Bundle
Download$89

Swarm Operator Kit

Run a team of AI agents as a business: charter, 5 roles, 6 skills, routines and scripts.

View Swarm Operator Kit
Download$19

n8n Agent Workflows

6 import-ready n8n workflows: x402 monitor, change alerts, Stripe log, AI digest and more.

View n8n Agent Workflows

Related

1 email a week: new x402 + MCP tools and free kits.

Short weekly digest of new x402 + MCP tools and free kits, including the MCP OAuth Checker. No spam, unsubscribe any time.