Skip to content

Claude Code Hooks

Summary

Automated triggers in Claude Code that run at specific lifecycle events (session start, pre-compact, session end), enabling automatic capture of conversation knowledge for the LLM Wiki pattern's internal data adaptation.

Three Hook Types

Session Start Hook

When: A new Claude Code session begins

What it does: - Loads AGENTS.md/CLAUDE.md so the agent understands the system it's operating in - Loads index.md so the agent knows where to start looking based on questions

Purpose: Gives the agent meta-reasoning about its environment from the moment it starts.

Pre-Compact Hook

When: Before context compaction (when the session is about to lose context)

What it does: - Sends the latest conversation messages to a separate LLM process (Claude Agent SDK) - Creates a summary of decisions made, lessons learned, action items - Writes the summary to a daily log file

Session End Hook

When: The Claude Code session closes

What it does: - Same as pre-compact — captures final takeaways from the conversation - Ensures nothing is lost when the session ends

Architecture

Both pre-compact and session end hooks call the Claude Agent SDK under the hood — a separate Claude process that receives the conversation transcript and produces a structured summary. This runs automatically, even using your Anthropic subscription without requiring a separate API key.

Daily Logs → Wiki Flush

Session logs are stored as daily files (equivalent to the raw/ folder). Once a day, a flush process: 1. Reads all daily logs 2. Extracts concepts and connections from them 3. Populates the wiki with structured, cross-referenced knowledge articles

Customization

  • Prompts for the compilation and flush processes can be edited directly
  • Claude Code can guide customizations because it has access to AGENTS.md
  • The system is self-contained and can improve itself

See Also