anthropics / anthropics/claude-code
[BUG] Sonnet 5 issues 1000 agents suddenly and burned 13M tokens for no reason
- Dominant language
- Python
- Stars
- 145k
- Forks
- 23.1k
- PR merge metrics
- PR metrics pending
Description
### Preflight Checklist
- [x] I have searched [existing issues](https://github.com/anthropics/claude-code/issues?q=is%3Aissue%20state%3Aopen%20label%3Abug) 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?
I asked it to simply code some text, but for some reason it catastrophicly failed. it read per character instead of array then it summons 1000 agents for now reason
[claude-code-workflow-bug-report.md](https://github.com/user-attachments/files/30386970/claude-code-workflow-bug-report.md)
### What Should Happen?
it should fEither (a) the platform detects that args was received as a raw string when the script's usage pattern clearly expects an object/array, and fails the call immediately with a clear diagnostic (e.g. "args was passed as a JSON string, not a parsed value — did you mean to pass an object/array directly?"), or (b) at minimum, a workflow that fans out to a number of agent()/parallel() calls far beyond the platform's own stated default guideline (this session's config said "keep workflows under 15 agents") should hard-stop with a warning instead of silently proceeding to spawn thousands of agents. Separately, a workflow racking up a long unbroken run of consecutive agent failures (e.g. "session limit" errors, which are non-retryable within the session) should stop scheduling further calls rather than continuing to the full 1000-call cap. And the completion line should reflect a catastrophic error rate (e.g. "completed — 800/1000 agent calls errored") instead of reading identically to a healthy run.ix the bug at least if it should think that summoning 1000 agents is suspicious
### Error Messages/Logs
```shell
agent_count: 1000, agents_done: 200, agents_error: 800, agents_skipped: 0, agents_empty_result: 0
subagent_tokens: 13,300,136, tool_uses: 3,926, duration_ms: 6,883,157 (~115 min)
[discover:0] blocked by safety classifier: Stage 2 classifier error - blocking based on stage 1 assessment
[discover:20]/[discover:21] handed row-id lists ["e"] / ["x"] — not real ids, flagged back by the sub-agent
[discover:206] ... [discover:999] failed: You've hit your session limit · resets 6:30pm (Asia/Tokyo)
parallel[1000] ... parallel[3824]+ failed: Workflow agent() call cap reached (1000). This usually means a
loop using budget.remaining() never terminates because no token budget was set — remaining() returns
Infinity when budget.total is null. Add a hard iteration cap to the loop, or pass a token budget.
```
### Steps to Reproduce
const groups = Object.entries(args)
const results = await parallel(
groups.map(([name, ids]) => async () => {
return await agent(`Your row ids (${ids.length}): ${JSON.stringify(ids)}`, { label: 'discover:' + name })
}),
)
### Claude Model
Sonnet (default)
### Is this a regression?
Yes, this worked in a previous version
### Last Working Version
_No response_
### Claude Code Version
2.1.219
### Platform
Anthropic API
### Operating System
macOS
### Terminal/Shell
Windows Terminal
### Additional Information
_No response_
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the reproduction's agent(), parallel(), and budget.remaining() calls, then trace how fan-out limits, session-limit failures, and completion summaries are handled. Done means suspiciously large workflows and repeated non-retryable failures stop safely, raw-string arguments are diagnosed, and catastrophic error counts are reflected in the final summary.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- ai, cli, tooling
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100