Skip to main content
MindStudio
Pricing
Blog About
My Workspace

Claude Code Hooks: 18 Lifecycle Events Most Users Have Never Touched — and How to Use Them

Claude Code has hooks at 18+ lifecycle events — session start, post-compaction, pre-response, and more. Most users ignore them entirely.

MindStudio Team RSS
Claude Code Hooks: 18 Lifecycle Events Most Users Have Never Touched — and How to Use Them

Claude Code Has 18 Lifecycle Hook Events. Almost Nobody Uses Them.

Hooks are described, by people who’ve spent serious time inside Claude Code, as “the most underutilized and misunderstood feature” in the entire platform. That’s a strong claim for a tool that also ships with agent teams, browser automation, and scheduled tasks. But spend an hour with the hooks documentation and you’ll understand why: hooks don’t look like a feature. They look like plumbing.

They are plumbing. And that’s exactly why you should care.

Claude Code fires hooks at 18+ lifecycle events — session start, post-compaction, pre-response, and more. You can attach automated actions to any of them. Most users have never opened the hooks configuration. This post explains what hooks actually do, which events matter most, and how to start using them without building anything complicated.


The Feature That Breaks Everyone’s Brain

Mark Kashef, who consults businesses on agentic operating systems, put it plainly in a recent breakdown of Claude Code architecture: hooks are “this weird innocuous thing that no one touches.” He’s spoken about them multiple times on his channel. Those videos, he notes, consistently underperform. Even business owners who are actively running Claude Code setups daily haven’t touched them.

The reason isn’t complexity. A hook is conceptually simple: it’s an event that fires at a defined moment in Claude Code’s lifecycle, and you attach an action to it. The confusion comes from the fact that most Claude Code tutorials focus on the conversational layer — prompts, models, context windows — and hooks live one level below that, in the infrastructure.

Think of it this way. When you’re building a Claude Code workflow, you’re mostly thinking about what Claude does. Hooks let you define what happens around what Claude does. Before it responds. After the conversation compacts. When a new session starts. Those are different control points, and they’re surprisingly reliable.


What Hooks Actually Do (With Real Examples)

The simplest hook demo is also the most illustrative. You can configure Claude Code to block any message containing a specific word — say, “pizza” — and the conversation just stops. No reply. Nothing. Send “hey” and it responds normally. Send “pizza” again and it goes silent. That’s a pre-response hook: an action that fires before Claude generates output, based on a condition you define.

A more practical version of the same pattern: block any request where Claude appears to be about to expose an API key or secret credential. You define the condition, Claude Code checks it before responding, and if it matches, the action fires. No human in the loop required.

On the output side, you can attach a hook that fires after Claude replies. The example from Jono Catliff’s complete Claude Code guide is a sound notification — a noise plays every time Claude finishes a response. Trivial as a demo, but the pattern scales. You could trigger a webhook, write to a log file, or update a summary document every time Claude completes a task.

The hooks that matter most for production setups, though, are the ones tied to session management.


The Post-Compaction Hook Is the One You Actually Need

Here’s the problem hooks solve that nothing else does cleanly.

Claude Code’s context window has a hard limit. When a conversation fills up — which happens faster than most people expect, because token costs compound exponentially as conversations grow longer — Claude automatically compacts the conversation. It summarizes everything and resets the context window so the session can continue.

The compaction itself is fine. The problem is what gets lost in it. Core context about who you are, what your business does, what constraints apply to this project — all of that can get compressed away. After compaction, you’re often starting a conversation with an agent that has forgotten the things it most needs to know.

The post-compaction hook solves this directly. You configure it to inject a block of context — your business description, your role, the rules that govern this project — immediately after every compaction event. The agent comes back from compaction already knowing what it needs to know. You don’t repeat yourself. The session continues without degradation.

Kashef describes this as one of the most reliable uses of hooks in a production agentic setup. The hook fires deterministically. It doesn’t depend on Claude remembering to ask. It doesn’t require you to notice that compaction happened. It just runs.


Session-Start Hooks and the Cold-Start Problem

TIME SPENT BUILDING REAL SOFTWARE
5%
95%
5% Typing the code
95% Knowing what to build · Coordinating agents · Debugging + integrating · Shipping to production

Coding agents automate the 5%. Remy runs the 95%.

The bottleneck was never typing the code. It was knowing what to build.

The same logic applies at session start. Every new Claude Code conversation begins cold — no memory of previous sessions, no context about your project unless you explicitly provide it. The claude.md file handles some of this, but hooks give you a more dynamic injection point.

A session-start hook can pull in context that’s specific to the current moment: today’s date, the current state of a file, a summary of recent activity. If you use Obsidian for notes, Kashef’s setup pulls in Obsidian files relevant to the current project folder automatically at session start. The agent begins with situational awareness instead of a blank slate.

This matters especially for agent teams. When you’re running an orchestrator pattern — one manager agent delegating to parallel employee agents — the cold-start problem multiplies. Each sub-agent starts without context. Kashef’s recommended fix is to load the orchestrator agent with the full roles and responsibilities of all sub-agents, so there’s no mismatch about which agent should handle which task. Hooks reinforce this by ensuring that context gets injected at the right moment, not just hoped for.

The self-evolving memory system built with Obsidian and Claude Code hooks takes this further — using hooks to automatically capture session logs and extract lessons into a persistent knowledge base. That’s the more ambitious version of what a session-start hook enables.


How to Create a Hook (It’s Simpler Than You Think)

You don’t need to write hook configuration files manually. You can ask Claude Code to build one for you.

The pattern Kashef describes: open a conversation, tell Claude what you want to happen and when, and ask it to create the hook. “Please create a hook that makes a sound every time you reply” — Claude builds it. “Please create a hook that injects my business context after every compaction” — Claude builds that too.

The hooks live in your project’s configuration. Claude Code’s sub-agent system includes a “Claude Code guide” sub-agent specifically designed to help with this kind of setup. You ask it to create a hook, it writes the configuration, and you’re done.

What you need to know going in:

  • Which event you want to hook. Session start and post-compaction are the two highest-value events for most users. Pre-response hooks are useful for blocking or filtering. Post-response hooks are useful for notifications and logging.
  • What action you want to fire. This can be a bash command, a file write, an injection of text into the context, or a call to an external service.
  • What condition, if any, should trigger it. Some hooks fire unconditionally (every compaction, every session start). Others fire based on conditions you define (message contains a specific word, file matches a pattern).

That’s the full mental model. The 18+ events are the menu. You pick the ones that match your workflow.


The Bigger Architecture Problem Hooks Are Solving

Hooks don’t exist in isolation. They’re one layer in what Kashef calls an agentic operating system — a stack that runs from data infrastructure at the bottom to automations and hooks at the top.

Everyone else built a construction worker.
We built the contractor.

🦺
CODING AGENT
Types the code you tell it to.
One file at a time.
🧠
CONTRACTOR · REMY
Runs the entire build.
UI, API, database, deploy.

The layers, roughly: your identity and rules (claude.md files, compliance constraints), your knowledge (files, MCPs, skills), your workers (agents with defined roles), and your automations (hooks, scheduled tasks, integrations). Most people building with Claude Code are operating at the worker layer without having built the layers beneath it. That’s why their setups feel unstable — they’re running agents on top of disorganized data and no persistent context.

Hooks are the mechanism that makes the automation layer reliable. They’re how you ensure that the right information is present at the right moment, without depending on Claude to remember or the user to repeat themselves.

This is also where the /compact command and context management intersect with hooks. Running /compact manually at around 50% context capacity — not waiting for automatic compaction at 100% — keeps session quality high. A post-compaction hook then ensures the recovery is clean. The two practices compound.


What the Silver Platter Skill Reveals About Your Setup

If you want a fast read on whether your Claude Code setup is actually ready to use hooks effectively, Kashef’s Silver Platter skill is worth running. It’s a slash command — /silver_platter — that audits your existing Claude Code configuration: your claude.md files, your skills, your rules, your integrations.

The audit takes 10 to 50 seconds. It outputs an HTML data map with three sections: a pantry (your core services and databases), a prep table (what you can do with that data), and a plate (what you can actually put to work). There’s also a data flow tab showing relationships between your systems, and a 30-day plan.

The skill interviews you — fast track or thorough — to understand your business context before generating the map. In Kashef’s own demo, it identified 38 skills, 16 rules, and a structured output pipeline, then generated specific recommendations for hooks and automations based on what was actually present.

The point isn’t the HTML output. The point is that most people running Claude Code don’t have a clear picture of what they’ve built. The Silver Platter skill forces that inventory, and the hook recommendations that come out of it are grounded in your actual setup, not generic advice.

For teams building more complex agent infrastructure, platforms like MindStudio handle orchestration across 200+ models and 1,000+ integrations with a visual builder — useful when you’re chaining agents and workflows that need to connect to business tools beyond what Claude Code’s native MCP servers cover.


Three Setups Where Hooks Change the Outcome

The practical difference hooks make becomes clearest in specific scenarios.

E-commerce operator (Marco pattern): Running Shopify, QuickBooks, TikTok, and a CSV empire. The problem is that pulling six months of sales data bloats the context window with JSON and metadata before any analysis happens. A pre-session hook that injects pre-aggregated summary tables — revenue, cost of goods sold, key metrics — means the agent starts analyzing immediately instead of spending 80% of the session retrieving data.

Law firm associate (Sally pattern): Working with confidential client matter files, Outlook, and Amazon Bedrock (because everything needs to be contained). A post-compaction hook that re-injects matter context after every compaction prevents the agent from losing track of case details mid-session. A session-start hook that loads the current matter’s summary file means every conversation begins with the relevant context already present.

RWORK ORDER · NO. 0001ACCEPTED 09:42
YOU ASKED FOR
Sales CRM with pipeline view and email integration.
✓ DONE
REMY DELIVERED
Same day.
yourapp.msagent.ai
AGENTS ASSIGNEDDesign · Engineering · QA · Deploy

Healthcare provider (Dr. Sana Anwar pattern): Dealing with Athena Health, EHR data, and HIPAA constraints. Here, hooks aren’t optional — they’re a compliance mechanism. A pre-response hook that checks whether any message is about to send protected health information to Anthropic’s servers can block that transmission before it happens. The data bifurcation between clinical and billing systems gets enforced at the hook level, not just hoped for at the prompt level.

These aren’t hypothetical. They’re the three personas Kashef walks through explicitly when demonstrating how the same hook architecture applies across completely different business contexts.


The Compaction Timing Problem (And Why It Matters for Hooks)

One detail that changes how you think about hooks: Claude Code’s context quality starts degrading at around 50% full, not at 100%. By the time automatic compaction fires, you’ve already been operating in a degraded state for the second half of the session.

This is why the /compact command exists as a manual option, and why running it early matters. But it’s also why the post-compaction hook is more important than it might seem. If you’re compacting at 50% to preserve quality, you’re compacting more frequently — which means the hook fires more frequently, and the context injection happens more often. The hook becomes a regular part of the session rhythm, not an edge case.

If you’re building applications that emerge from this kind of iterative, session-based work, tools like Remy take a different approach to the source-of-truth problem: you write an annotated markdown spec, and the full-stack app — TypeScript backend, SQLite database, auth, deployment — gets compiled from it. The spec is what you maintain; the code is derived output. It’s a different layer of abstraction, but the underlying principle — keeping your source of truth clean and explicit — is the same one that makes hooks worth configuring carefully.


Where to Start

If you’ve never touched hooks, the post-compaction hook is the right first one. It solves a real problem (context loss after compaction), it fires deterministically, and it’s easy to configure by asking Claude Code to build it for you.

The prompt is simple: “Please create a post-compaction hook that injects the following context after every compaction: [your business description, your role, the key rules for this project].” Claude Code will write the configuration. You review it, approve it, and it runs from that point forward.

After that, the session-start hook is the natural second step — especially if you’re running agent teams where cold-start context mismatches are causing problems. And if you’re working in a domain with compliance constraints, the pre-response filtering hook moves from nice-to-have to necessary.

The 18 lifecycle events are documented. The hooks themselves are straightforward to create. The gap between knowing they exist and actually using them is mostly a matter of knowing which ones to start with.

Start with post-compaction. The rest follows from there.

Presented by MindStudio

No spam. Unsubscribe anytime.