Files
claude-mem/docs/reference/claude-code/session-start-hook.md
T
thedotmack 598369e894 Initial release v3.3.8
- Hook system for customization
- Documentation and installation scripts
- Multi-platform support via GitHub releases
- Binaries available for Windows, Linux (x64/ARM64), macOS (Intel/Apple Silicon)

Generated with Claude Code via Happy
2025-09-06 19:34:53 +00:00

2.5 KiB

SessionStart Hook Documentation

Official Documentation Reference

Hook Payload Structure

The SessionStart hook receives the following JSON payload via stdin:

{
  "session_id": "string",
  "transcript_path": "string", 
  "hook_event_name": "SessionStart",
  "source": "startup" | "compact" | "vscode" | "web"
}

Field Descriptions

  • session_id: Unique identifier for the Claude Code session
  • transcript_path: Path to the conversation transcript JSONL file
  • hook_event_name: Always "SessionStart" for this hook
  • source: Indicates how the session was initiated:
    • "startup": New session started normally (should load context)
    • "compact": Session started after compaction (may skip context)
    • "vscode": Session initiated from VS Code extension
    • "web": Session initiated from web interface

Response Format

The hook should output JSON in the following format to add context:

{
  "hookSpecificOutput": {
    "hookEventName": "SessionStart",
    "additionalContext": "string"
  }
}

Response Fields

  • hookSpecificOutput: Container for hook-specific output
  • hookEventName: Must be "SessionStart"
  • additionalContext: String content to add to the session context

Implementation Notes

Context Loading Strategy

The hook should determine whether to load context based on the source field:

  1. For "startup" source: Load full context from memory
  2. For "compact" source: Skip or load minimal context (session continuing after compaction)
  3. For "vscode"/"web" sources: Load context as appropriate

Error Handling

  • If context loading fails, exit silently (exit code 0)
  • Do not break the session start with errors
  • Log errors to separate log file if needed

Common Mistakes

Incorrect Field Check (FIXED)

Wrong: Checking payload.reason === 'continue' Correct: Checking payload.source === 'compact'

The payload does not have a reason field. The source field indicates the session initiation context.

Code Location

  • File: /Users/alexnewman/Scripts/claude-mem/hooks/session-start.js
  • Line: 53-66 (field check and documentation)

Cross-References