context-injection
2 questions
- 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
What does a UserPromptSubmit hook actually do for a vague 'where was I?' prompt?
A captured `claude --print` session against the demo app, with a UserPromptSubmit hook that appends the current branch, last 3 commits, and `git diff --stat` to every prompt as additional context. The user prompted 'Summarize what work is currently in flight in this repo' with two real uncommitted changes on disk (a `cancelAllForCitizen` stub method and a `describe.skip` test placeholder). Claude's thinking block named 'git status and recent commits' as its source, then ran 2 Bash calls to read the actual diff content, then produced a one-paragraph summary. The article shows the wire format of the hook's injection, the events.jsonl gap (UserPromptSubmit fires with zero visible system events), and the Bash-matcher footgun where `git -C /path diff` failed to match the `Bash(git diff:*)` allow rule because of the `-C` flag prefix.