跳到正文
原文
Hacker News · 首页· zzyyxx332211·· 19 天前精选AI 评分45

开发者开源 agent-usage-guard:Claude Code 用量保护 hook

Show HN: agent-usage-guard – a Claude Code mod to protect your usage window

AI 导读

开发者因多次在几分钟内耗尽 Claude Code 用量额度,开发并开源了 agent-usage-guard,一个基于 hooks 的 Claude Code mod,可在缓存过期、内容过大时提示用户先 compact 再发送,并在用量窗口超过 80% 时阻止子代理生成。

推荐理由

作者公开了开源工具的实测数据,展示如何用 hook 控制 Claude Code 用量消耗,对重度用户有直接参考价值。

正文 · 原文

After consuming my whole usage window in a few minutes multiple times, I realised I needed a hook to do some checks for me and prompt me before submitting when cache had expired and content is too big, so that it can suggest me to "compact then send". It can also prevent sub-agents from spawning when above 80% usage window. Control is handed over to the user.

The first I built, based on hooks (run for 75 days), the biggest burst fell from 365 agent spawned to 27, and requests over 500k tokens of context from 14.5% to 0.6%. Lockouts still went up, because lots of parallel main sessions use up the window too. The strength is that it counts agents across every session on the machine.

I built https://github.com/rbartoli/agent-usage-guard, MIT-licensed, makes no network calls, needs Claude Code 2.1.287 or later.

I have also a post on this: https://rblab.com/what-stops-claude-code-burning-your-usage-...

来源:Hacker News · 首页 · news.ycombinator.com