ClaudeMods
☰
ZH-TW
● 0 人在線上 · 瀏覽 0 次
贊助提交作品
Reddit 貼文 · 發布者 rbartoli

十分鐘內 394 個子代理讓我被鎖在 Claude Code 之外,所以我做了一個先詢問的模組

一個 Claude Code 模組,agent-usage-guard,限制並行子代理和代理啟動次數,在消耗計畫視窗配額前提示,並拒絕相同的重試迴圈。免費且 MIT 授權,透過外掛市場安裝。

已翻譯

關於這個 mod

在一次工作階段中,十分鐘內生成了 394 次子代理呼叫(341 次並行)和 8400 萬上下文權杖,觸發了使用鎖定後建置。該模組作為行程內鉤子執行:將所有本機 Claude Code 工作階段中的代理限制為 4 個並行和每 10 分鐘啟動 12 次,阻止子代理生成自己的代理,在 5 小時或每週計畫視窗達到 80% 時詢問是否啟動新代理,在 95% 時拒絕,在超過 50 萬權杖的重度重讀前提示,在提示快取過期後恢復重度工作階段時提示,並在連續三次相同失敗後拒絕相同的重試。核准會持續到條件清除。在 claude -p 中,它拒絕並給出原因,而不是提示。/agent-guard report 顯示活動。TypeScript,無相依性,86 個測試,無網路呼叫。

安裝

安裝方式請查看原始來源。

原文 / 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]

更多類似作品