Claude Code Hooks Template
The two highest-value Claude Code hooks: auto-format every file the agent edits, and hard-block edits to paths that must never be touched.
{
"hooks": {
"PostToolUse": [
{
"matcher": "Edit|Write",
"hooks": [
{
"type": "command",
"command": "jq -r '.tool_input.file_path // empty' | xargs -r npx prettier --write --ignore-unknown"
}
]
}
],
"PreToolUse": [
{
"matcher": "Edit|Write|Bash",
"hooks": [
{
"type": "command",
"command": "jq -r '.tool_input | tostring' | grep -qE '\.env|migrations/|\.git/' && { echo 'Blocked by hook: this touches a protected path (.env, migrations/, .git). Ask the user before modifying these.' >&2; exit 2; } || exit 0"
}
]
}
]
}
}How to use
Merge the hooks block into .claude/settings.json in your repo (or ~/.claude/settings.json globally). How it works: each hook shells out with the tool call's JSON on stdin, the PostToolUse hook extracts the edited file path and runs Prettier on it (swap in your formatter), and the PreToolUse hook greps the tool input for protected paths and exits with code 2, which blocks the action and feeds the stderr message back to Claude as guidance. Edit the grep pattern to your own protected paths, and verify your setup with the /hooks command. Hooks are deterministic where CLAUDE.md is advisory. Use them for the rules that must never be broken.
More agent prompts
You are a software engineering agent working in the [PRODUCT/TEAM] codebase ([LANGUAGE/STACK]). Your objective is to take an assigned task from description to verified, working code. You may read and modify anything in the repository; you do not push, merge, deploy, or alter CI configuration unless the task explicitly says to. # Operatin
Coding Agent System Prompt
Autonomous coding agent that matches repo conventions, proves work with passing tests before claiming done, and reports failures truthfully.
You are a debugging agent for the [PRODUCT] codebase. Your objective is to find the root cause of a reported bug, fix it with the smallest possible change, and prove the fix. You are not here to refactor, harden, or improve unrelated code: a debugging session that ends in a 40-file diff has failed even if the bug is gone. # Reproduce Bef
Debugging Agent System Prompt
Root-cause-first debugging agent: no fix until the bug is reproduced, minimal diffs only, and done means the repro dies while the test suite stays green.
You are a code migration agent. Your objective is to move the [PRODUCT] codebase from [SOURCE VERSION/FRAMEWORK] to [TARGET VERSION/FRAMEWORK] while preserving behavior exactly. You are a mechanical translator with judgment, not a redesigner: the product must work the same after every step you take. # The Prime Rule: Migration Changes On
Code Migration Agent System Prompt
Framework-upgrade agent that migrates in build-green slices, verifies every codemod, follows official guides over memory, and never mixes in behavior changes.