Claude Code Hooks 5 Automations That Eliminate Developer Friction
Section titled “Claude Code Hooks 5 Automations That Eliminate Developer Friction”Coding Nexus is a community of developers, tech enthusiasts, and aspiring coders. Whether you’re exploring the depths of Python, diving into data science, mastering web development, or staying updated on the latest trends in AI, Coding Nexus has something for you.
Stop clicking approve buttons and losing flow state. These hooks turn Claude Code from a polite assistant into a teammate.
You know that moment when everything is clicking.
You’ve got the problem loaded in your head. The solution is halfway formed. Your fingers are moving faster than you can consciously think. This is the good part of coding. The rare part.
And then…
Claude wants permission to write a file.*
Click approve.
Claude wants to run a command.
Click approve.
Claude edited a file but it’s not formatted.
Click approve.
Claude wants to run tests.
Click approve.*
Twenty tiny interruptions later, the thread is gone. Not dramatically. Not all at once. Just… diluted. You’re still coding, but the sharpness is missing. Flow state slipped out while you weren’t looking.
That’s the real problem Claude Code hooks solve.
Not speed.
Not intelligence.
Friction.
And once you see them for what they are, it’s hard to go back.

The mental tax we don’t talk about
Section titled “The mental tax we don’t talk about”Here’s what I’ve noticed after using Claude Code heavily.
The highest cost isn’t waiting. It’s context switching.
Every approval dialogue forces your brain to answer a question it already knows the answer to. “Yes, formatting is fine.” “Yes, running tests is safe.” “Yes, write the file.”
Those decisions are trivial, but they’re still decisions. And decisions break flow.
Hooks let you move those decisions out of your head and into configuration. You decide once. Claude executes forever.
Think of hooks like reflexes. Automatic responses to predictable situations. No thinking required.
Before we go deep, here’s the smallest possible hook that delivers immediate value.
Add this to .claude/settings.json:
{ "hooks": { "PostToolUse": [{ "matcher": "Write|Edit", "hooks": [{ "type": "command", "command": "npx prettier --write \"$CLAUDE_TOOL_INPUT_FILE_PATH\"" }] }] }}That’s it.
Every file Claude writes, or edits, is now auto-formatted. No approval. No reminder. No “I’ll fix it later.”
You keep thinking about the feature. Claude worries about whitespace.
Once you feel how smooth that is, you’ll want more.
What Claude Code hooks actually are
Section titled “What Claude Code hooks actually are”At a mechanical level, hooks are simple.
They listen for events within Claude Code and execute shell commands when those events occur. That’s it. No magic. No hidden state.
But the leverage comes from when those events fire.
Here’s the full set, as a quick reference:
| Hook | When It Fires | Best Use || ----------------- | -------------------------- | ----------------------------------- || PreToolUse | Before any tool runs | Block dangerous operations || PostToolUse | After tool completes | Auto-format, lint, log || PermissionRequest | Before permission dialog | Auto-approve safe commands || SessionStart | Session begins | Inject context (git status, TODOs) || Stop | Claude finishes responding | Run tests, validate output || PreCompact | Before context compaction | Backup transcripts || SubagentStop | Subagent completes | Validate agent output || UserPromptSubmit | You hit enter | Inject instructions, validate input |If that table feels abstract, don’t worry. It clicks once you see real use cases.
So let’s walk through five hooks that actually change how it feels to code.
Hook 1: Auto-format on every write
Section titled “Hook 1: Auto-format on every write”We’ve already seen the basic version; let’s extend it.
Here’s what it looks like when you stack formatting and linting:
{ "hooks": { "PostToolUse": [{ "matcher": "Write|Edit", "hooks": [ {"type": "command", "command": "npx prettier --write \"$CLAUDE_TOOL_INPUT_FILE_PATH\""}, {"type": "command", "command": "npx eslint --fix \"$CLAUDE_TOOL_INPUT_FILE_PATH\""} ] }] }}A small but important detail: multiple hooks run in parallel.
So Claude writes a file.
Prettier formats it.
ESLint fixes what it can.
And only then do you see the response.
The code you read is already clean.
No “we’ll tidy this up later.”
No slow decay of standards over time.
Just a quiet guarantee that every edit meets your baseline.
Honestly, this alone is worth using hooks.
Hook 2: Session context injection
Section titled “Hook 2: Session context injection”One of the subtle frustrations with AI coding tools is that every session starts cold.
You know the state of the repo.
Claude doesn’t.
Hooks fix that.
With a SessionStart hook, you can inject context automatically before you say a word:
{ "hooks": { "SessionStart": [{ "hooks": [{ "type": "command", "command": "echo '## Current State' && git status --short && echo '## Active TODOs' && grep -r 'TODO:' src/ --include='*.ts' | head -5" }] }] }}Now, when a session starts, Claude sees:
- Uncommitted changes
- Which files are dirty
- A snapshot of active TODOs
You don’t have to explain what you were doing yesterday. Or remind Claude that there’s half-finished work in auth.ts.
It’s like walking into a conversation where the other person already knows what you were talking about last time.
That alone changes the tone of the interaction.
Hook 3: Auto-approve commands you already trust
Section titled “Hook 3: Auto-approve commands you already trust”This is where hooks start to feel a little rebellious.
Permission dialogues are supposed to protect you. And that’s good.
But approving npm test for the 400th time isn’t safety. It’s a ritual.
Enter PermissionRequest.
{ "hooks": { "PermissionRequest": [{ "matcher": "Bash(npm test*)", "hooks": [{ "type": "command", "command": "echo '{\"decision\": \"approve\"}'" }] }] }}This hook intercepts the permission request and responds with JSON:
{ "decision": "approve" }No interruption. Tests just run.
And yes, you should be careful here.
Only auto-approve commands you genuinely trust.
But for things like npm test, pnpm lint, or cargo test, this is pure signal over noise.
Your attention stays where it belongs.
Hook 4: Run tests automatically when Claude finishes
Section titled “Hook 4: Run tests automatically when Claude finishes”Here’s one that feels small until you live with it.
A Stop hook runs when Claude finishes responding.
Perfect moment to validate what just changed.
{ "hooks": { "Stop": [{ "hooks": [{ "type": "command", "command": "npm test --passWithNoTests 2>&1 | tail -20" }] }] }}Every time Claude finishes:
- Tests run
- Failures appear immediately
- Output is trimmed to the useful bits
You don’t have to remember to run tests.
You don’t have to ask Claude to do it.
Feedback is automatic.
This tightens the loop in a way that’s hard to overstate. Bugs stop travelling far. Bad assumptions get caught early. You stay honest without extra effort.
It’s quite disciplined.
Hook 5: Skill activation without relying on memory
Section titled “Hook 5: Skill activation without relying on memory”This one’s a bit more advanced, but powerful.
The idea is simple: before Claude sees your prompt, you automatically append extra instructions.
That’s what UserPromptSubmit is for.
{ "hooks": { "UserPromptSubmit": [{ "hooks": [{ "type": "command", "command": "node .claude/hooks/SkillActivationHook/skill-activation-prompt.mjs" }] }] }}Now, when you type something vague like:
“implement a feature”
Claude also sees internal guidance about which skills to activate. Architecture mode. Refactoring mode. Debugging mode. Whatever you’ve defined.
No prompt gymnastics.
No relying on long-term memory.
Just consistent behavior.
It’s a quiet way of steering the model without micromanaging it.
Where hooks live
Section titled “Where hooks live”You can configure hooks in three places:
LocationScopeUse Case.claude/settings.json Project (shared)Team standards.claude/settings.local.json Project (personal)Your preferences ~/.claude/settings.json All projectsGlobal defaults
Project settings override user settings.
This matters more than it sounds. It lets teams agree on non-negotiables (formatting, tests) while individuals keep personal optimizations.
Hooks scale surprisingly well socially.
When things go wrong
Section titled “When things go wrong”A few hard-earned lessons.
Hook not triggering?
Check the matcher.
Write|Edit works.
Write | Edit (with spaces) doesn’t.
Command failing silently?
Add logging:
your-command 2>&1 | tee ~/.claude/hook-debug.logEverything feels slow?
Hooks have a 60-second timeout. If something’s heavy, run it in the background or trim the output.
Hooks are powerful, but they’re still just shell commands. Treat them like production code. Because they kind of are.
Start with one. Seriously.
Section titled “Start with one. Seriously.”If all of this feels like a lot, that’s okay. Don’t boil the ocean.
Pick the friction that annoys you the most:
- Constant formatting —
PostToolUse - Endless approvals —
PermissionRequest - Missing context —
SessionStart - Forgetting tests —
Stop
Fix one thing.
Then live with it for a few days. You’ll feel the difference. And once you do, adding the next hook won’t feel like configuration. It’ll feel like relief.
Coding Nexus is a community of developers, tech enthusiasts, and aspiring coders. Whether you’re exploring the depths of Python, diving into data science, mastering web development, or staying updated on the latest trends in AI, Coding Nexus has something for you.
Responses (1)
Section titled “Responses (1)”Talbot Stevens
What are your thoughts?
I haven't used Claude yet. As a Codex user I'm feeling pretty good right now that I can simply place AGENTS.md files in folders, with markdown and common text instructions, and avoid the need for yet another structured paradigm and JSON schema. Thoughts?More from Civil Learning and Coding Nexus
Section titled “More from Civil Learning and Coding Nexus”Recommended from Medium
Section titled “Recommended from Medium”[
See more recommendations


