Skip to content

session-end Hook

Generates structured session summaries and archives session state when a Claude Code session ends


session-end Hook

The session-end hook fires when a Claude Code session ends. It generates a structured summary from all observations captured during the session, captures conversation turns and tool call details from the transcript, marks the session as completed, and auto-generates/archives the CURRENT.md session state file.

Trigger Event

Fires once when the Claude Code session stops (user exits or session times out).

What It Does

  1. Collects all observations for the current session from the memory database
  2. Collects all user prompts captured by the user-prompt hook
  3. Generates a structured summary including:

- Original request (first user prompt) - Discoveries and investigations - Decisions made - Work completed (features, bugfixes, refactors) - Failed attempts - Next steps (if work is incomplete) - Files created and modified - Verification results (VR pass/fail) - Plan progress tracking

  1. Captures conversation data by parsing the JSONL transcript (incremental -- only new lines)
  2. Marks session as completed in the database
  3. Archives CURRENT.md and generates a fresh one

Example Input

json
{
  "session_id": "abc123-def456",
  "transcript_path": "/Users/dev/.claude/projects/my-app/transcript.jsonl",
  "cwd": "/Users/dev/my-app",
  "hook_event_name": "stop"
}

Summary Structure

The generated summary includes these fields:

FieldSourceDescription
requestFirst user promptWhat the user asked for
investigatedDiscovery observationsWhat was explored
decisionsDecision observationsArchitectural choices made
completedFeature/bugfix/refactor observationsWork finished
failedAttemptsFailed attempt observationsWhat did not work
nextStepsLast 10% of observationsWhat to do next
filesCreatedFile change observationsNew files
filesModifiedFile change observationsChanged files
verificationResultsVR check observationsPass/fail results
planProgressPlan item observationsPlan completion tracking

Conversation Capture

The session-end hook also parses the JSONL transcript to capture:

  • Conversation turns: User prompts paired with assistant responses
  • Tool call details: Tool name, input summary, I/O sizes, success/failure, files touched
  • Token estimates: Approximate token counts per turn

This data powers the observability tools (massu_session_replay, massu_prompt_analysis, massu_tool_patterns).

Tips

  • The session-end hook uses incremental transcript parsing -- it tracks the last processed line to avoid re-processing
  • Assistant responses are capped at 10,000 characters to prevent database bloat
  • The hook runs best-effort -- it never blocks Claude Code from shutting down