[BUG] Opus 4.7 halts turn early after PreToolUse hook emits additionalContext on 2 calls

Resolved 💬 1 comment Opened May 29, 2026 by oakif Closed Jul 1, 2026

What's Wrong?

When a PreToolUse:Bash hook returns hookSpecificOutput.additionalContext on two Bash calls within ~3 calls of each other, Opus 4.7 ends its turn early: stop_reason=end_turn, empty content, no further tool_use. Sonnet 4.6 and Haiku 4.5 don't halt with the same hook output.

The trigger is additionalContext itself, not its text, even "[hello]" repeated twice causes it. updatedInput rewrites without additionalContext are fine.

What Should Happen?

Opus should continue the task like Sonnet and Haiku do.

Steps to Reproduce

Save as /tmp/break_opus.py and chmod +x:

#!/usr/bin/env python3
import json, sys
from pathlib import Path
STATE = Path("/tmp/break_opus_state"); STATE.mkdir(exist_ok=True)
event = json.loads(sys.stdin.read())
if event.get("tool_name") != "Bash":
    json.dump({"hookSpecificOutput": {"hookEventName": "PreToolUse"}}, sys.stdout); sys.exit(0)
sid = event.get("session_id") or "x"
f = STATE / f"{sid}.txt"
try: count = int(f.read_text())
except: count = 0
f.write_text(str(count + 1))
out = {"hookSpecificOutput": {"hookEventName": "PreToolUse"}}
if count < 2:
    out["hookSpecificOutput"]["additionalContext"] = "[hello]"
json.dump(out, sys.stdout)

Register as a PreToolUse:Bash hook, then run:

claude -p --model opus --dangerously-skip-permissions --output-format=stream-json --verbose \
  'Run as 6 separate Bash calls, reporting each: pwd; cd /tmp && ls; pwd; echo "$PWD"; cd ~/Developer && pwd; ls -la. Summarize.'

Observed: num_turns=4, result_len=0. Halts after ~3 tool calls.
Expected: All 6 calls + summary.

Change count < 2 to count < 1 → completes. Or keep < 2 and use --model sonnet / --model haiku → completes.

Bisection

| Pattern | Opus | Sonnet | Haiku |
| --- | --- | --- | --- |
| 0 injections | ✓ | ✓ | ✓ |
| 1 injection | ✓ | ✓ | ✓ |
| 2 consecutive | ✗ halts | ✓ | ✓ |
| 2 with 1-call gap | ✗ halts | ✓ | ✓ |
| 2 with 3-call gap | ✓ | ✓ | ✓ |

Claude Code Version

2.1.150 (Claude Code). Same behavior in 2.1.140 (VS Code extension).

Platform

Anthropic API.

OS

macOS.

Terminal/Shell

Non-interactive (claude -p) and VS Code integrated terminal. Both reproduce.

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗