[Bug] Anthropic API Error: Spurious token emission at tool-call boundaries in high-redundancy sessions
Bug Description
Title: Degenerate token-repetition at tool-call boundaries in long, structurally-repetitive sessions (consistent court signature)
Summary: In long-running agentic sessions, the model intermittently fails at the moment it transitions into emitting a tool call. It emits a spurious court token immediately before the
tool-call markup. In the dominant failure mode it locks into repeating court and the turn stalls/stops with no recovery; less often it spews court unboundedly, and occasionally court
leaks as a one-off prefix before an otherwise-valid call that then proceeds.
Signature (highly consistent across ~20–30 occurrences over several weeks, multiple independent sessions):
- Always the token court.
- Always at a tool-call boundary (immediately preceding <invoke …> / function-call XML). Example of the benign-prefix form: court followed by a valid <invoke name="Bash">…</invoke>.
- Dominant outcome: the driving turn stops and does not self-resume; a human message is required to continue. (One observed session self-recovered; most did not.)
Conditions / apparent trigger:
- Occurs deep in long sessions with high context redundancy/self-similarity — the same large skill document (~90 KB) re-injected verbatim many times (5+), plus dozens of near-identical
tool calls and near-identical narration.
- The trigger appears to be redundancy, not raw length: injecting diverse natural-language content (a freeform conversation) increases total tokens yet reliably pulls the model out of
the loop and keeps it stable. Entropy/diversity of recent context, not token count, seems to be the operative variable.
- The consistency of court (vs. an arbitrary repeated token) suggests a structural issue in the tool-call transition path rather than a generic repetition attractor.
Impact: Breaks unattended/autonomous operation — a nondeterministic halt that requires human intervention to resume.
Repro: Not deterministically reproducible, but probability rises sharply with session length × context self-similarity, especially when the same large skill/system text is re-injected
per iteration. The attached transcript contains both a clean malignant occurrence and a stable recovery after the context was diversified.
Environment: Claude Code; model Opus 4.8 (1M context); macOS (darwin). Surfaced in a skill-driven, ScheduleWakeup-re-entrant agent loop.
Environment Info
- Platform: darwin
- Terminal: vscode
- Version: 2.1.191
- Feedback ID: f5840535-c129-47c1-aa47-0a2a4f47c854
Errors
[]This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗