{
  "markdown": "# claude-hooks — Claude Code Hook System\n\n**7 hooks for Claude Code, built from 6 months of daily use. Covers safety, context injection, auto-formatting, model routing, and session lifecycle.**\n\n---\n\n## Hooks\n\n| Hook | Trigger | What it does | Requires |\n|------|---------|--------------|----------|\n| `smart-map.sh` | Session start (`UserPromptSubmit`, first prompt) | Injects project file tree + code definitions into context | `jq` |\n| `auto-commit.sh` | After Edit/Write (`PostToolUse`) | Creates micro-commits after file edits — instant undo checkpoints | `git` |\n| `safety-net.sh` | Before Bash (`PreToolUse`) | Blocks destructive commands: `rm -rf`, `DROP TABLE`, force-push, etc. | `jq` |\n| `enforce-style.sh` | After Edit/Write (`PostToolUse`) | Auto-formats Python (Ruff/Black) and JS/TS (Prettier) on save | `ruff` or `black`, `prettier` |\n| `notify-done.sh` | Session stop (`Stop`) | macOS notification when Claude Code task completes | macOS only |\n| `smart-archive.sh` | Session stop (`Stop`) | Archives completed `PLAN.md` / `TODO.md` to `.archive/` | none |\n| `route-model.sh` | Every prompt (`UserPromptSubmit`) | Classifies prompt type and nudges model switching when there's a mismatch | Python 3, `model-router.py` |\n\n---\n\n## Hook details\n\n### `smart-map.sh`\nFires once per session on the first prompt. Generates a project tree (2 levels deep, ignoring `node_modules`, `__pycache__`, `.git`), git status, and an \"X-Ray\" view of Python class/function definitions and TypeScript/JavaScript exports. Injects everything as `additionalContext` so Claude has immediate project awareness without you having to explain the layout.\n\n### `auto-commit.sh`\nAfter every `Edit` or `Write` tool call, stages the modified file and creates a `Claude checkpoint: <file>` commit. Gives you a complete undo history of every change Claude made — roll back with `git log` + `git checkout`. Uses `--no-verify` to skip pre-commit hooks.\n\n### `safety-net.sh`\nIntercepts `Bash` tool calls and blocks a curated list of dangerous patterns before execution:\n- `rm -rf` (recursive force delete)\n- Deletion of root or home directories\n- `npm publish` / `yarn publish` / `pnpm publish`\n- Force-push to `main` or `master`\n- `DROP DATABASE` / `DROP TABLE` / `DROP SCHEMA`\n- `chmod 777`\n- `curl ... | bash` (remote script execution)\n\nReturns exit code `2` to block the tool call and surfaces an error message to Claude.\n\n### `enforce-style.sh`\nAfter every `Edit` or `Write` call, detects the file extension and runs the appropriate formatter:\n- `.py` → Ruff (preferred) or Black (fallback)\n- `.js`, `.jsx`, `.ts`, `.tsx`, `.json`, `.css`, `.scss`, `.md`, `.yaml`, `.yml` → Prettier\n\nSilent if the formatter isn't installed.\n\n### `notify-done.sh`\nUses `osascript` to fire a macOS notification with sound when Claude Code's session ends. Useful when running long tasks in the background.\n\n### `smart-archive.sh`\nOn session stop, checks for `PLAN.md`, `plan.md`, `TODO.md`, and `todo.md` in the project root. If all tasks are checked off (no `[ ]`, `TODO:`, or `FIXME:` markers remain), moves the file to `.archive/<timestamp>_<filename>`. Keeps your project root clean without losing the history.\n\n### `route-model.sh`\nClassifies every prompt using `model-router.py` (keyword heuristics, no LLM calls) and compares the result against the currently active model. If there's a mismatch above the confidence threshold (default: 0.4), injects a one-line nudge like `> Model suggestion: this looks like a planning task — consider switching to Opus`. Configure with env vars:\n- `MODEL_ROUTER_MODE=quiet` — disables nudges entirely\n- `MODEL_ROUTER_MIN_CONFIDENCE=0.6` — raise the bar before nudging\n- `MODEL_ROUTER_CURRENT_MODEL=sonnet` — override model detection\n\n---\n\n## Installation\n\nSee [INSTALL.md](INSTALL.md) for full setup instructions.\n\n---\n\n## What's not included\n\nThree hooks from the original system are excluded because they depend on Kernel-specific infrastructure:\n- `dangerous-action-gate.sh` — integrates with Kernel's approval queue\n- `action-approval-handler.sh` — Kernel webhook receiver\n- `auto-logger.sh` — writes to Kernel's structured log system\n\n---\n\n## License\n\nMIT\n",
  "bytes": 4168,
  "sha": "894f66a377140d23a0a8c9ef205eb52a280405360402a262ed1c350e0bd9a4ff",
  "repo_slug": "rjspence3/claude-hooks",
  "fonte": "repo",
  "truncated": false,
  "api": "https://agentalog.com/api/listings/plg_rjspence3_claude_hooks_the_safety_net_e88ccc04/readme"
}