Skip to content

session-start Hook

Injects cross-session memory context when a new Claude Code session begins


session-start Hook

The session-start hook fires when a Claude Code session begins (startup, resume, or after compaction). It reads the memory database and injects relevant context from previous sessions directly into the conversation, giving your AI assistant immediate awareness of past decisions, failures, and progress.

Trigger Events

SourceWhenToken Budget
startupNew session starts2,000 tokens
resumeSession is resumed1,000 tokens
compactAfter context compaction4,000 tokens
clearAfter context clear2,000 tokens

The compact source gets the highest token budget because compaction destroys context that needs to be restored.

What It Does

  1. Creates a session record in the memory database with the current git branch
  2. Links to task if a plan file reference is detected
  3. Builds prioritized context from multiple sources:

- Failed attempts (highest priority -- DO NOT RETRY warnings) - Current session observations (after compaction) - Recent session summaries - Cross-task progress tracking - Recent observations sorted by importance

  1. Fills token budget from highest-importance sections first
  2. Outputs plain text that Claude Code injects into the conversation

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": "session_start",
  "source": "startup"
}

Example Output

=== Massu Memory: Previous Session Context ===

### Failed Attempts (DO NOT RETRY)
- drizzle-kit push fails with RLS-enabled tables (2x)
- next-auth getServerSession returns null in middleware

### Session (2026-02-10)
**Task**: Implement database migration system
**Completed**: Added migration CI check, fixed timeout handling
**Plan**: 4/5 complete

### Recent Observations
- [decision|imp:8] Chose Prisma migrate over raw SQL (2026-02-10)
- [bugfix|imp:7] Fixed migration timeout with lock_timeout (2026-02-09)

=== END Massu Memory ===

Context Priority Order

PrioritySectionWhy
10Failed attemptsPrevents repeating known-bad approaches
9Current session observationsRestores context after compaction
8Cross-task progressMaintains task continuity
7Session summariesProvides background context
5Recent observationsGeneral knowledge

Configuration

The session-start hook uses these config sections:

  • team.enabled: If true, includes team-shared observations
  • Session and observation data comes from the memory database

No explicit hook configuration is needed -- it works automatically.