SessionStart Hook - Claude Code
Fires when a session begins; load env vars and initialize state.
SessionStart fires once when Claude Code starts a session. It's the place for environment setup, secret loading, and "run this every time" initialization.
What it does
The hook runs after config loads but before the first user prompt. It can export environment variables that persist across Bash calls, print a welcome banner, run a health check, or pull a secret from a vault. Its return value can inject context into the session.
When to use it
- Loading API keys or credentials from a secret manager.
- Pulling the latest CLAUDE.md or rules from a central source.
- Warming caches for tools Claude will likely need.
- Emitting a project-specific banner so you know which context you're in.
Gotchas
- Slow SessionStart hooks make startup feel sluggish. Keep them fast or run async.
- Failing hooks can block a session. Default to fail-open unless failure should truly stop work.
- Env vars set here persist into Bash calls but not into shells you launched before the session started.
Official docs: https://code.claude.com/docs/en/hooks.md#sessionstart
Technical content at the intersection of AI and development. Building with AI agents, Claude Code, and modern dev tools - then showing you exactly how it works.
Get the weekly deep dive
Tutorials on Claude Code, AI agents, and dev tools - delivered free every week.
Was this helpful?




