ClaudeMods
☰
EN
● — online · Views — times
SponsorsSubmit a project
Reddit posts · by rbartoli

394 subagents in ten minutes locked me out of Claude Code, so I built a mod that asks first

A Claude Code mod, agent-usage-guard, that caps concurrent subagents and agent starts, prompts before burning plan-window quota, and refuses identical retry loops. Free and MIT, installed via the plugin marketplace.

Translated

About this mod

Built after a session that spawned 394 subagent calls (341 concurrent) and 84M context tokens in ten minutes, triggering a usage lockout. The mod runs as in-process hooks: it limits agents to 4 concurrent and 12 starts per 10 minutes across all local Claude Code sessions, blocks subagents from spawning their own agents, asks before starting new agents at 80% of a 5-hour or weekly plan window, refuses at 95%, prompts before heavy re-reads over 500k tokens, prompts on resuming a heavy session after prompt cache expiry, and refuses identical retries after three consecutive identical failures. Approvals persist until the condition clears. In claude -p it refuses with a reason instead of prompting. /agent-guard report shows activity. TypeScript, no dependencies, 86 tests, no network calls.

Installation

See the original source for installation instructions.

Original text / README

One afternoon I gave Claude Code a research prompt at max effort. It made 394 subagent calls, 341 of them running at once, and pushed 84M context tokens through the API in ten minutes. Then "Claude usage limit reached": locked out until the window reset. Sixty days of my logs held 12 lockouts like it. So I built agent-usage-guard, a Claude Code mod (mods are the in-process hooks Claude Code added in 2.1.287). It acts before the spend, not after: Agents: 4 running at once and 12 starts per 10 minutes, counted across every Claude Code session on your machine. Subagents can't start their own. Plan window: from 80% of your 5-hour or weekly window, new agents ask first; from 95% they're refused. Heavy context: a prompt that would re-read 500k+ tokens asks to compact first, send anyway, or cancel. A heavy session resumed after its prompt cache expired asks too. Loops: after three identical failures in a row, the identical retry is refused. It asks in Claude Code's own question dialog, and one approval covers the condition until it clears, so the same question doesn't come back call after call. In claude -p it refuses with a reason instead, so Claude can wait, batch the work or stop. /agent-guard report shows what it did. The video is Claude Code's real UI running against a scripted local API: the sessions and token counts are staged, and no usage was spent recording it. How I built it: with Claude Code, in TypeScript with no dependencies; 86 tests run in Claude Code's own mod test kit. Its first version was plain hooks, which I ran for 75 days: my largest agent burst fell from 365 starts in ten minutes to 27. It hasn't cut my lockouts yet. Those come from many main sessions running in parallel, which is what I'm working on next. Free, MIT, no network calls. Install in Claude Code 2.1.287+: /plugin marketplace add rbartoli/agent-usage-guard /plugin install agent-usage-guard@agent-usage-guard /reload-plugins https://github.com/rbartoli/agent-usage-guard Which default would you change first? submitted by /u/rbartoli [link] [comments]

Similar projects