Feature Request: SessionStart hook for pre-session initialization
Description
I'd like to request a SessionStart hook that fires when a Claude Code session begins, before the first user message is processed. This would allow users to run custom initialization logic at startup.
Use Case
I've built a personal knowledge/memory system that integrates with Claude Code. Currently I rely on CLAUDE.md instructions to tell Claude what to do at startup (read files, query APIs, display context). But this is fragile - it depends on Claude following instructions rather than guaranteed execution.
A SessionStart hook would let me:
- Automatically query my external system for relevant context
- Inject session-specific information before the conversation begins
- Load prior session state reliably
- Run environment setup scripts
Proposed Solution
Add a SessionStart hook similar to existing SessionEnd hooks:
{
"hooks": {
"SessionStart": [
{
"type": "command",
"command": "/path/to/init-session.sh"
}
]
}
}
SessionStart hook input (JSON via stdin):
{
"session_id": "...",
"cwd": "...",
"git_branch": "...",
"resumed": false
}
SessionStart hook output (optional, via stdout):
{
"inject_context": "Context to add to system prompt: ...",
"env_vars": {"KEY": "value"}
}
Benefits
- Guaranteed initialization rather than instruction-dependent behavior
- Enables reliable integration with external systems
- Symmetric with existing SessionEnd hooks
- Allows project-specific context injection based on working directory
- Supports session resumption awareness
Related
This complements #17237 (PreCompact/PostCompact hooks) - together they would enable full lifecycle context management for users building persistent memory systems.
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗