agent_type in SessionStart Hook
Feature works as documented. The agent_type field is populated when --agent is specified with a valid agent name.
The agent_type field in SessionStart hook input is a conditional identifier populated only when the --agent flag specifies a valid agent.
How it works
When a Claude Code session starts with the --agent flag (e.g., claude --agent test-agent-type), the SessionStart hook receives input JSON containing a new agent_type field set to the agent name. Without the flag, the field is not present. Built-in agents (Explore, Plan) and custom agents both populate the field equally.
What the test found
Runtime testing (2026-01-16, Claude 2.1.2 on 2.1.9) confirmed the feature through five scenarios:
- Without
--agent: Noagent_typefield in hook input - With valid custom agent (
--agent test-agent-type):agent_typepopulated correctly - With valid built-in agent (
--agent Explore):agent_typepopulated correctly - With invalid agent (
--agent nonexistent-agent): No field present, no error raised - With
-pprint mode: SessionStart hook did not fire when combined with--agent, but fired without it
The field appears in the JSON structure at top level alongside session_id, hook_event_name, and source.
Why it matters
Hook scripts can now condition behavior on agent type without shell inspection of CLI arguments. A SessionStart hook can adapt initialization (logging, routing, permissions) based on whether the session runs under a specific agent identity.
Caveats
Invalid agent names fail silently, omitting the field rather than raising an error. The -p mode shows inconsistent hook firing behavior that may be unintended. The field's absence (no agent specified) is indistinguishable from a nonexistent agent in hook input alone.
- file2.1.2/tests/01-agent-type-hook/TEST-RESULTS.md
primitive_cc5d1f2926d0263e22286abded255199b87705613b1e2fd064d57fa75a6b679d2856ceafad6b1daa8f982493871b6ddf3b715d8b78ddabf3c8c29728e2d2e2878a7a1463d789998e3e6553de694979cb7f7d1c68039190196c9d241b9bd3918ea162c94978d3f64b0399a9bc50f5f05Signed with an ed25519 key held off the repo. Anyone can verify against the published public key; nobody without the secret key can forge it. Click verify: it recomputes the signature in your browser. The signature proves integrity and authorship of this exact content — not a third-party timestamp or that the underlying claim is objectively true. signedAt is when the @f3/attest pipeline ran, not when the work happened; the evidence refs carry the source dates.
- instance-of Event Interposition Class
- introduces (in) Claude Code 2.1.2 Feature Testing (2.1.2) Release
- verifies (in) agent_type in SessionStart Hook — runtime test Test