[BUG] SessionStart prompt hooks crash with unhandled exception

Status Fixed / completed
Reported on v2.1.109
Maintainer reply None cached
Activity 5 comments · opened Apr 15, 2026 · closed May 13, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Bug: SessionStart prompt hooks crash with unhandled exception

Summary

A SessionStart hook of type: "prompt" throws an unhandled exception on every session start. The exception message itself reads "This is a bug," suggesting the platform team may already be aware, or it's a generalized catch-all response. Reporting to confirm it is reproducible across platforms and versions, and to document the impact on plugin development.

---

Environment

  • Claude Code version: 2.1.109
  • Platforms: Ubuntu 24.04.4 LTS (x86_64), Raspberry Pi OS Lite 64-bit (aarch64) — reproduced on both

---

Steps to reproduce

  1. Create a hooks.json with a SessionStart prompt hook:
  {               
    "hooks": {
      "SessionStart": [
        {
          "hooks": [                                                                                        
            {
              "type": "prompt",                                                                             
              "prompt": "Your instruction here."
            }
          ]
        }
      ]
    }
  }
  1. Start a new Claude Code session.

---

Actual behavior

The session crashes immediately with:

ToolUseContext is required for prompt hooks. This is a bug.

---

Expected behavior

The prompt hook fires at session start and the model executes the instruction before the user's first message.

---

Additional notes

  • type: "command" hooks at SessionStart work — but only inject output as a <system-reminder>. The model does not act on it until the user sends their first message, making it unsuitable for auto-executing instructions on open.
  • ${CLAUDE_PLUGIN_ROOT} expands correctly in command hooks but not in prompt hooks.
  • The primary use case blocked by this bug: plugins that need to auto-run a startup routine (e.g. load session context, deliver a sitrep, custom greeting/instruction) when a session opens, without requiring the user to type a command first.

What Should Happen?

The prompt hook fires at session start and the model executes the instruction before the user's first message.

Error Messages/Logs

ToolUseContext is required for prompt hooks. This is a bug.

Steps to Reproduce

  1. Create a hooks.json with a SessionStart prompt hook:

```
{
"hooks": {
"SessionStart": [
{
"hooks": [
{
"type": "prompt",
"prompt": "Your instruction here."
}
]
}
]
}
}

   
  2. Start a new Claude Code session.

### Claude Model

Sonnet (default)

### Is this a regression?

I don't know

### Last Working Version

_No response_

### Claude Code Version

2.1.109

### Platform

Anthropic API

### Operating System

Ubuntu/Debian Linux

### Terminal/Shell

Terminal.app (macOS)

### Additional Information

_No response_

View original on GitHub ↗

5 Comments

jarvis-raven · 6 months ago

Confirming on macOS — same error on Darwin 25.2.0 (macOS 26.2), Claude Code 2.1.112. Identical minimal repro: type: "prompt" hook on SessionStart throws ToolUseContext is required for prompt hooks. This is a bug. at session start. The platform:linux label probably wants widening — this isn't platform-specific.

emersonfarias · 5 months ago

Confirming still reproduces on macOS (Darwin 24.6.0) with Claude Code 2.1.114. Same minimal repro: type: "prompt" hook on SessionStart throws ToolUseContext is required for prompt hooks. This is a bug. on every session start. The sibling type: "command" hook in the same block fires normally, so the regression is isolated to prompt hooks.

massy-na · 5 months ago

Confirming still reproduces on Windows 11 Pro with Claude Code 2.1.119.

Minimal repro matches the original: a project-scoped .claude/settings.json containing a type: "prompt" SessionStart hook throws ToolUseContext is required for prompt hooks. This is a bug. immediately on session start. Sibling type: "command" hooks in the same block keep firing normally, so the regression is isolated to the prompt-hook dispatcher.

Two data points that may be worth adding:

  • Not plugin-specific. The issue body describes a plugin hooks.json, but the same error fires for a hook defined directly in project-level settings.json with no plugin involved. The failure looks like it is in the prompt-hook dispatcher itself, independent of plugin loading.
  • Windows reproduction. Existing labels are platform:macos and platform:linux; verified here on native Windows (not WSL) with a fresh session. platform:windows may want widening.

Reproducer (.claude/settings.json):

{
  "hooks": {
    "SessionStart": [
      {
        "hooks": [
          { "type": "prompt", "prompt": "test" }
        ]
      }
    ]
  }
}
wirelessml · 5 months ago

Confirming on Claude Code 2.1.123 / macOS 15.7 (Darwin 25.5.0) — same minimal repro (type: "prompt" hook on SessionStart throws ToolUseContext is required for prompt hooks. This is a bug.).

Adding a previously-unreported downstream-impact data point: this bug interacts with /remote-control (and presumably remoteControlAtStartup: true) to cause a hard, user-visible failure beyond the cosmetic banner.

Failure mode

  1. New session starts; SessionStart prompt hook errors with ToolUseContext is required for prompt hooks. The hook_non_blocking_error is recorded as an attachment in the session's local transcript.
  2. Within ~8 s of startup, user runs /remote-control.
  3. Backend session creation hangs for 27.8 s then returns Remote Control failed to connect: Session creation failed — see debug log. The CLI shows only Remote Control connecting… during the wait.
  4. Same /remote-control invoked ~20 min later succeeds in 0.8 s.

Transcript-side measurements (same session, no other variables):

| metric | failed (10:26 JST) | retry (10:47 JST) |
| --- | --- | --- |
| time since session start | 8.2 s | ~20 min |
| attachments in immediate window | 8 (incl. hook_non_blocking_error) | 0 |
| transcript bytes accumulated | 50.3 KB | 51.3 KB (Δ = +1 KB) |
| outcome | 27.8 s → Session creation failed | 0.8 s → bridge active |

Payload size is essentially identical between attempts; the only meaningful difference is the dirty-hook-state attachment in the failed window. May be worth cross-referencing with #52775 (the other known SessionStart-hook × remote-control interaction bug).

github-actions[bot] · 3 months ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.