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.
Found 2 possible duplicate issues:
- https://github.com/anthropics/claude-code/issues/11316
- https://github.com/anthropics/claude-code/issues/10808
This issue will be automatically closed as a duplicate in 3 days.
- If your issue is a duplicate, please close it and 👍 the existing issue instead
- To prevent auto-closure, add a comment or 👎 this comment
🤖 Generated with Claude Code
Not a Duplicate - Addressing Different Architectural Layer
Thank you for flagging potential overlaps. After reviewing #10808 and #11316, I believe this issue addresses a distinct and foundational concern.
Scope Comparison:
| Issue | Layer | Purpose |
|---|---|---|
| #17278 | Hook Infrastructure | Execute arbitrary initialization commands at session start; inject context into system prompt |
| #10808 | User Interface | Enable Claude to send autonomous messages after hook execution |
| #11316 | Agent Workflow | Allow subagents to execute read-only tools before generating proposals |
Key Distinction:
This request (#17278) focuses on the execution infrastructure itself—providing a mechanism to run custom scripts and return structured context at session initialization. This is architecturally symmetric with the existing SessionEnd hook.
In contrast:
- #10808 addresses message delivery after hooks complete
- #11316 addresses agent-specific tool access during prompt generation
These features operate at different layers and are complementary rather than duplicative. Notably, the autonomous messaging capability proposed in #10808 would benefit from the hook infrastructure proposed here.
I'd recommend keeping this issue open to track the core hook mechanism separately from downstream features that may build upon it.
This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.
Closing for now — inactive for too long. Please open a new issue if this is still relevant.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.