sessionstart
3 questions
- AI
Which hook event should I use? The full list, ranked.
Claude Code exposes 28 hook events across five categories: lifecycle, tool execution, turn control, agent teams, and context management. Exit code 2 blocks the action on blocking events. Non-blocking events show stderr but cannot prevent what already happened.
- AI
What does a SessionStart hook actually do for the agent in a real session?
A captured `claude --print` session against the demo app, with a SessionStart hook that runs `git log -5` plus working-tree status and injects the result as `additionalContext`. The prompt asked about recent feature work and forbade running `git log` manually. Claude used the commit SHA from the injected context to jump straight to `git show <sha>` and produced a substantive coverage analysis in four tool calls. The article shows the hook config, the script, the events.jsonl output that proves the hook fired, and what Claude visibly did with the context that saved a redundant tool call.
- AI
Setup or SessionStart hook for my install script?
SessionStart fires on every session start, resume, `/clear`, and post-compaction, so it has to be fast. Setup fires only on explicit `claude --init-only`, `claude -p --init`, or `claude -p --maintenance`, which makes it the right home for slow one-time work like dependency installs or scheduled cleanup. Neither hook can block Claude from starting; for hard preconditions, gate the `claude` binary, not the hook.