Live
Black Hat USADark ReadingBlack Hat AsiaAI BusinessAssessing Marvell Technology (MRVL) After Nvidia’s US$2b AI Partnership And Connectivity Push - simplywall.stGNews AI NVIDIADutchess to host artificial intelligence summit at Marist in Poughkeepsie - Daily FreemanGoogle News: AIAnthropic’s Catastrophic Leak May Have Just Handed China the Blueprints to Claude Al - TipRanksGoogle News: ClaudeOpenAI's Fidji Simo Is Taking Medical Leave Amid an Executive Shake-UpWired AIMeta's AI push is reshaping how work gets done inside the companyBusiness InsiderOpenAI's Fidji Simo Is Taking Medical Leave Amid an Executive Shake-Up - WIREDGoogle News: OpenAI[P] Remote sensing foundation models made easy to use.Reddit r/MachineLearningFirst time NeurIPS. How different is it from low-ranked conferences? [D]Reddit r/MachineLearningAI & Tech brief: Ireland ascendant - The Washington PostGNews AI EUPeople would rather have an Amazon warehouse in their backyard than a data centerTechCrunch AITake-Two lays off its head of AI and several team members just two months after the CEO said it was embracing Gen AI - TweakTownGoogle News: Generative AIOpenAI Buys TBPN Tech Talk Show for Enterprise Client Outreach - News and Statistics - IndexBoxGoogle News: OpenAIBlack Hat USADark ReadingBlack Hat AsiaAI BusinessAssessing Marvell Technology (MRVL) After Nvidia’s US$2b AI Partnership And Connectivity Push - simplywall.stGNews AI NVIDIADutchess to host artificial intelligence summit at Marist in Poughkeepsie - Daily FreemanGoogle News: AIAnthropic’s Catastrophic Leak May Have Just Handed China the Blueprints to Claude Al - TipRanksGoogle News: ClaudeOpenAI's Fidji Simo Is Taking Medical Leave Amid an Executive Shake-UpWired AIMeta's AI push is reshaping how work gets done inside the companyBusiness InsiderOpenAI's Fidji Simo Is Taking Medical Leave Amid an Executive Shake-Up - WIREDGoogle News: OpenAI[P] Remote sensing foundation models made easy to use.Reddit r/MachineLearningFirst time NeurIPS. How different is it from low-ranked conferences? [D]Reddit r/MachineLearningAI & Tech brief: Ireland ascendant - The Washington PostGNews AI EUPeople would rather have an Amazon warehouse in their backyard than a data centerTechCrunch AITake-Two lays off its head of AI and several team members just two months after the CEO said it was embracing Gen AI - TweakTownGoogle News: Generative AIOpenAI Buys TBPN Tech Talk Show for Enterprise Client Outreach - News and Statistics - IndexBoxGoogle News: OpenAI
AI NEWS HUBbyEIGENVECTOREigenvector

5 Claude Code Hooks That Automate My Entire Workflow

DEV Communityby DevForge TemplatesApril 2, 20265 min read0 views
Source Quiz

<p>Claude Code hooks are shell commands that fire at specific lifecycle events. They're configured in <code>.claude/settings.json</code> and run automatically — no manual intervention.</p> <p>I use 5 hooks across all my projects. Here's each one with the exact config.</p> <h2> 1. Auto-Format After Every File Write </h2> <p>Every time Claude writes or edits a file, Prettier runs on it automatically.<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight json"><code><span class="p">{</span><span class="w"> </span><span class="nl">"hooks"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="nl">"PostToolUse"</span><span class="p">:</span><span class="w"> </span><span class="p">[{</span><span class="w"> </span><spa

Claude Code hooks are shell commands that fire at specific lifecycle events. They're configured in .claude/settings.json and run automatically — no manual intervention.

I use 5 hooks across all my projects. Here's each one with the exact config.

1. Auto-Format After Every File Write

Every time Claude writes or edits a file, Prettier runs on it automatically.

{  "hooks": {  "PostToolUse": [{  "matcher": "Write|Edit",  "hooks": [{  "type": "command",  "command": "jq -r '.tool_response.filePath // .tool_input.file_path' | { read -r f; prettier --write \"$f\"; } 2>/dev/null || true"  }]  }]  } }

Enter fullscreen mode

Exit fullscreen mode

Why: Claude's code formatting is inconsistent. Sometimes it uses 2 spaces, sometimes 4. Prettier fixes it instantly. The || true ensures the hook never blocks Claude if Prettier fails.

2. Inbox Check on Every Message

Every time I send a message, Claude checks its message bus inbox for tasks from other agents.

{  "hooks": {  "UserPromptSubmit": [{  "hooks": [{  "type": "command",  "command": "~/.claude/bus/check-inbox.sh my-agent"  }]  }]  } }

Enter fullscreen mode

Exit fullscreen mode

The script checks if ~/.claude/bus/inbox-my-agent.md has content. If yes, it prints the messages. Claude sees them and acts on them before responding to my message.

Why: This is how my 6 agents communicate. No polling interval — messages are delivered the moment I interact with any agent.

3. Session Context on Start

When a new session starts, automatically load the last session's state.

{  "hooks": {  "SessionStart": [{  "hooks": [{  "type": "command",  "command": "cat docs/SESSION-HANDOFF.md 2>/dev/null && echo '---' && cat .claude/rules/known-issues.md 2>/dev/null || true"  }]  }]  } }

Enter fullscreen mode

Exit fullscreen mode

Why: Claude reads the handoff file and known issues automatically. No need to say "read the handoff file" at the start of every session. It just knows what happened last time.

4. Reminder Before Session Ends

When Claude stops (session end, context limit, or user stops), remind it to save state.

{  "hooks": {  "Stop": [{  "hooks": [{  "type": "command",  "command": "echo '{\"systemMessage\": \"REMINDER: Update docs/SESSION-HANDOFF.md with what was done, what failed, and what is next.\"}'"  }]  }]  } }

Enter fullscreen mode

Exit fullscreen mode

Why: Without this, Claude often stops mid-task without saving context. The reminder fires every time, so the handoff file stays current.

5. Protect Critical Files

Before any edit to protected files, block the write.

{  "hooks": {  "PreToolUse": [{  "matcher": "Edit|Write",  "hooks": [{  "type": "command",  "command": "jq -r '.tool_input.file_path // \"\"' | grep -qE '(\\.env|credentials|secrets)' && echo '{\"decision\": \"block\", \"reason\": \"Cannot edit sensitive files\"}' || true"  }]  }]  } }

Enter fullscreen mode

Exit fullscreen mode

Why: Claude occasionally tries to write API keys or modify .env files. This hook blocks any edit to files matching sensitive patterns. It's a safety net you set once and forget.

The Hook Lifecycle

Here's when each hook type fires:

Event When Use case

SessionStart New session begins Load context

UserPromptSubmit You send a message Check inbox

PreToolUse Before a tool runs Block dangerous actions

PostToolUse After a tool succeeds Format code, run tests

Stop Session ends Save state

PreCompact Before context compression Preserve critical info

Setting It Up

All hooks go in .claude/settings.json (project-level) or ~/.claude/settings.json (global).

# Create project settings mkdir -p .claude cat > .claude/settings.json << 'EOF' {  "hooks": {  "PostToolUse": [{  "matcher": "Write|Edit",  "hooks": [{  "type": "command",  "command": "echo 'file written'"  }]  }]  } } EOF

Enter fullscreen mode

Exit fullscreen mode

Start simple. Add one hook. Verify it fires. Then add more.

Common Mistakes

  1. Missing || true — If your hook command fails, it can block Claude entirely. Always add || true unless you intentionally want to block on failure.

  2. Hooks that are too slow — Hooks run synchronously by default. A hook that takes 10 seconds runs on every single tool call. Keep them fast.

  3. Forgetting the JSON output format — Stop hooks need to output JSON with systemMessage field. Plain text won't show up.

These 5 hooks run across 16 projects. Once set up, they work silently in the background. The best automation is the kind you forget exists.

Was this article helpful?

Sign in to highlight and annotate this article

AI
Ask AI about this article
Powered by Eigenvector · full article context loaded
Ready

Conversation starters

Ask anything about this article…

Daily AI Digest

Get the top 5 AI stories delivered to your inbox every morning.

Knowledge Map

Knowledge Map
TopicsEntitiesSource
5 Claude Co…claudeupdateglobalsafetyagentclaude codeDEV Communi…

Connected Articles — Knowledge Graph

This article is connected to other articles through shared AI topics and tags.

Knowledge Graph100 articles · 135 connections
Scroll to zoom · drag to pan · click to open

Discussion

Sign in to join the discussion

No comments yet — be the first to share your thoughts!