---
title: "十分钟内 394 个子代理让我被锁在 Claude Code 之外，所以我做了一个先询问的模组"
url: "https://claudemods.dev/zh-cn/builds/394-subagents-in-ten-minutes-locked-me-out-of-claude-code-so-93a2e9"
source: "https://www.reddit.com/r/ClaudeAI/comments/1x1r82v/394_subagents_in_ten_minutes_locked_me_out_of"
source_type: "reddit"
author: "rbartoli"
author_handle: "rbartoli"
stars: 0
category: "用量与成本"
categories: ["cost"]
tags: ["cost-control", "hooks", "rate-limiting", "subagents", "usage-limits"]
permission_level: null
scan_complete: false
added: "2026-10-09T20:05:31.744Z"
updated: "2026-10-09T17:19:19.000Z"
locale: "zh-cn"
content_locale: "zh-cn"
---

# 十分钟内 394 个子代理让我被锁在 Claude Code 之外，所以我做了一个先询问的模组

一个 Claude Code 模组，agent-usage-guard，限制并发子代理和代理启动次数，在消耗计划窗口配额前提示，并拒绝相同的重试循环。免费且 MIT 许可，通过插件市场安装。

## Description

在一次会话中，十分钟内生成了 394 次子代理调用（341 次并发）和 8400 万上下文令牌，触发了使用锁定后构建。该模组作为进程内钩子运行：将所有本地 Claude Code 会话中的代理限制为 4 个并发和每 10 分钟启动 12 次，阻止子代理生成自己的代理，在 5 小时或每周计划窗口达到 80% 时询问是否启动新代理，在 95% 时拒绝，在超过 50 万令牌的重度重读前提示，在提示缓存过期后恢复重度会话时提示，并在连续三次相同失败后拒绝相同的重试。批准会持续到条件清除。在 `claude -p` 中，它拒绝并给出原因，而不是提示。`/agent-guard report` 显示活动。TypeScript，无依赖，86 个测试，无网络调用。

## Original 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]
