Claude Code Subagents & Hooks: Deterministic Guardrails + Parallel Speed
Stop repeating the same reminders in prompts. Put hard rules in hooks and keep your main context clean with subagents.
Most people use Claude Code like a single chat box — and then wonder why it slows down, forgets lint rules after 40 minutes, or burns through usage limits. Two features change everything: hooks (deterministic shell guardrails) and subagents (isolated parallel workers).
1. High-leverage Claude Code hooks (.claude/settings.json)
Never rely on a prompt alone for things that MUST happen every single time — formatting edited files, blocking force-pushes, or preventing edits to `.env` secrets. A PostToolUse hook runs automatically the millisecond an edit lands:
{
"hooks": {
"PostToolUse": [
{
"matcher": "Edit|Write",
"hooks": [
{
"type": "command",
"command": "jq -r '.tool_input.file_path' | xargs -r npx prettier --write"
}
]
}
],
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "jq -r '.tool_input.command' | grep -qE 'git push.*(--force|-f)|rm -rf /' && exit 2 || exit 0"
}
]
}
]
}
}2. Subagents: stop poisoning your main context window
Reading 35 files to understand an unfamiliar auth flow fills 60,000 tokens of your main session forever. Instead, delegate exploration to a read-only subagent that returns a 20-line map of exact file paths and line numbers.
- Research subagents: Fan out 3 read-only subagents in parallel to inspect frontend components, API handlers, and database migrations simultaneously.
- Adversarial review subagent: Before pushing, launch a fresh subagent with zero sunk-cost bias to review `git diff` purely for logic bugs, race conditions, and missing edge cases.
- Custom agent definitions: Save specialized prompts in
.claude/agents/(e.g.,db-migrator.md,seo-auditor.md) so the whole team invokes the same verified checklist.
Pair this setup with clean Claude Code MCP servers and read OpenCode vs Claude Code for monthly cost optimization tips.
Frequently asked questions
What is the difference between Claude Code hooks and CLAUDE.md instructions?
CLAUDE.md is advisory context the model reads and usually follows; hooks are deterministic shell commands executed by the harness before or after tool calls. Hooks cannot be forgotten when context gets long — if a PreToolUse hook exits non-zero, the action is blocked.
When should I use Claude Code subagents?
Use subagents whenever a task needs heavy file reading (mapping a codebase, tracing a bug across 30 files) or independent parallel work (auditing security, performance, and types at the same time). Each subagent gets a fresh context window and returns only a tight summary.
Where do Claude Code hooks live?
Personal global hooks live in ~/.claude/settings.json and repo-shared hooks live in .claude/settings.json under the "hooks" key (PreToolUse, PostToolUse, Notification, and Stop events).