claude-code - 💡(How to fix) Fix [BUG] /goal evaluator fires during background-shell wait windows, fragmenting agent execution [5 comments, 4 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#58677Fetched 2026-05-14 03:42:17
View on GitHub
Comments
5
Participants
4
Timeline
13
Reactions
1
Timeline (top)
commented ×5labeled ×4subscribed ×2mentioned ×1

The /goal evaluator currently treats the gap between a background-shell spawn and its completion notification as a turn boundary, firing a goal check during the wait window. The agent is not idle in this state — it has explicit pending work (a long-running Bash invocation started with run_in_background=true). The hook injects repeated "goal status" reminders into the agent's context, fragmenting execution and producing a stream of noise the agent may erroneously respond to instead of continuing to wait.

This is a trigger-timing bug, distinct from existing /goal issues that focus on what happens after the hook fires.

Root Cause

IssueFocusRelation to this report
#58550no circuit breaker — once stuck, burns tokens indefinitelyindependent — this report is about whether the hook should fire at all in this state
#58516hook reaches the wrong conclusion (Goal Achieved while TaskList has pending items)independent — noise is harmful regardless of conclusion
#58348 / #58465infinite loops from unsatisfiable conditions / ignored overridesindependent — but the same trigger-timing root cause amplifies all of these
RAW_BUFFERClick to expand / collapse

Summary

The /goal evaluator currently treats the gap between a background-shell spawn and its completion notification as a turn boundary, firing a goal check during the wait window. The agent is not idle in this state — it has explicit pending work (a long-running Bash invocation started with run_in_background=true). The hook injects repeated "goal status" reminders into the agent's context, fragmenting execution and producing a stream of noise the agent may erroneously respond to instead of continuing to wait.

This is a trigger-timing bug, distinct from existing /goal issues that focus on what happens after the hook fires.

Distinction from related issues

IssueFocusRelation to this report
#58550no circuit breaker — once stuck, burns tokens indefinitelyindependent — this report is about whether the hook should fire at all in this state
#58516hook reaches the wrong conclusion (Goal Achieved while TaskList has pending items)independent — noise is harmful regardless of conclusion
#58348 / #58465infinite loops from unsatisfiable conditions / ignored overridesindependent — but the same trigger-timing root cause amplifies all of these

Fixing trigger-timing here would incidentally mitigate #58550 and #58516 by reducing how often the evaluator runs in states where its output is meaningless or wrong.

The agent has three distinct states — the hook conflates two of them

StateWhenTurn truly ended?Hook should fire?
Tool-use in-flightagent emitted tool_use, awaiting resultNoNo (currently does not — correct)
Background-tool waitagent spawned a long-running shell with run_in_background=true; spawn returned, but the work is incomplete and the agent is awaiting the completion notificationNo — agent still has live, intentional pending workNo — but the hook does fire. This is the bug.
Truly idleagent has finished its intent and is awaiting fresh user inputYesYes

The hook appears to treat the absence of a new tool_use as evidence the agent is idle, collapsing state 2 into state 3.

Repro (conceptual)

  1. /goal <any non-trivial goal>
  2. Have the agent launch a long-running background shell, e.g.:
    • npm run dev
    • pytest tests/ --runslow (multi-minute run)
    • Any build / training / migration of several minutes
  3. Observe the goal evaluator firing during the wait window — once per evaluator cycle — while the shell is still running and the agent is doing nothing but waiting for the completion notification.
  4. Each fire injects a "goal status" reminder. The agent may:
    • respond to the reminder instead of continuing to wait
    • re-poll the background shell prematurely
    • drift to unrelated actions
    • in any case, fragment the planned execution flow

Expected

The evaluator fires only when the agent is truly idle — after the agent's final response with no pending background work the harness is tracking. Background-tool wait windows should be transparent to the evaluator.

Why it matters

  1. Tokens — each fire reprocesses full context. #58550 quantified ~50% weekly budget burn from analogous over-firing.
  2. Agent behavior — repeated reminders during a wait can cause the agent to abandon the wait, poll early, or branch into unrelated work, defeating the point of run_in_background.
  3. UX — long-running commands now generate visible hook-fire noise.
  4. Cascading risk — more fires → higher probability of #58516 false-positive Goal Achieved.

Note

This report is mechanism-level and does not include a captured transcript. Any sufficiently long run_in_background Bash invocation under an active /goal should reproduce. Happy to add a captured transcript if maintainers want one.

Environment

  • Reporter platform: Windows 11
  • Model: claude-opus-4-7
  • Claude Code version: 2.1.140

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] /goal evaluator fires during background-shell wait windows, fragmenting agent execution [5 comments, 4 participants]