claude-code - 💡(How to fix) Fix SessionStart hook fails with agent type: ToolUseContext is required [2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#46072Fetched 2026-04-11 06:29:43
View on GitHub
Comments
2
Participants
2
Timeline
6
Reactions
0
Timeline (top)
labeled ×3commented ×2closed ×1

Error Message

SessionStart:startup hook error The error message itself acknowledges this is a bug.

Root Cause

SessionStart fires before any tool call context exists. Agent hooks require ToolUseContext, which is only available during PreToolUse / PostToolUse events. This means "type": "agent" is currently incompatible with SessionStart (and likely Stop as well).

Code Example

SessionStart:startup hook error
Failed to run: ToolUseContext is required for agent hooks. This is a bug.

---

{
  "hooks": {
    "SessionStart": [
      {
        "matcher": "startup|resume",
        "hooks": [
          {
            "type": "agent",
            "prompt": "Read project files and summarize status",
            "timeout": 120
          }
        ]
      }
    ]
  }
}

---

Failed to run: ToolUseContext is required for agent hooks. This is a bug.
RAW_BUFFERClick to expand / collapse

Bug Description

When using "type": "agent" in a SessionStart hook, the hook fails with:

SessionStart:startup hook error
Failed to run: ToolUseContext is required for agent hooks. This is a bug.

The error message itself acknowledges this is a bug.

Steps to Reproduce

  1. Add the following to .claude/settings.json:
{
  "hooks": {
    "SessionStart": [
      {
        "matcher": "startup|resume",
        "hooks": [
          {
            "type": "agent",
            "prompt": "Read project files and summarize status",
            "timeout": 120
          }
        ]
      }
    ]
  }
}
  1. Start a new Claude Code session in the project directory.

Expected Behavior

The agent hook should execute at session start, running the specified prompt.

Actual Behavior

The hook fails immediately with:

Failed to run: ToolUseContext is required for agent hooks. This is a bug.

Analysis

SessionStart fires before any tool call context exists. Agent hooks require ToolUseContext, which is only available during PreToolUse / PostToolUse events. This means "type": "agent" is currently incompatible with SessionStart (and likely Stop as well).

Environment

  • OS: Windows 11 Home 10.0.26200
  • Claude Code: latest
  • Shell: bash

extent analysis

TL;DR

Change the hook type or move the agent hook to a compatible event like PreToolUse to resolve the incompatibility issue.

Guidance

  • Identify alternative events like PreToolUse or PostToolUse where ToolUseContext is available and agent hooks can be used.
  • Consider modifying the .claude/settings.json to use a different hook type that does not require ToolUseContext.
  • Verify the compatibility of the chosen hook type with the SessionStart event to avoid similar issues.
  • Review the documentation for any updates on using agent hooks with SessionStart or other events.

Example

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "tool-name",
        "hooks": [
          {
            "type": "agent",
            "prompt": "Read project files and summarize status",
            "timeout": 120
          }
        ]
      }
    ]
  }
}

Notes

The current implementation of agent hooks in SessionStart is acknowledged as a bug, and moving to a compatible event is a workaround until the issue is resolved.

Recommendation

Apply workaround: Move the agent hook to a compatible event like PreToolUse to utilize the required ToolUseContext. This change allows the agent hook to execute successfully while waiting for a fix for the SessionStart event compatibility issue.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix SessionStart hook fails with agent type: ToolUseContext is required [2 comments, 2 participants]