claude-code - 💡(How to fix) Fix [BUG] Opus 4.7 halts turn early after PreToolUse hook emits additionalContext on 2 calls

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…

Code Example

#!/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)

---

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.'
RAW_BUFFERClick to expand / collapse

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

PatternOpusSonnetHaiku
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.

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 [BUG] Opus 4.7 halts turn early after PreToolUse hook emits additionalContext on 2 calls