Context Diet:一个防止庞大工具输出淹没上下文的 Claude Code 模组
Context Diet 在 Claude 读取大型工具输出(测试运行、构建、差异、日志)之前对其进行裁剪,仅保留失败、摘要和相关结构,并将完整输出保存到文件以便后续检索。
关于这个 mod
一次测试运行或构建日志就能向 Claude 的上下文中倾倒 30–50k 字符,其中几乎全是噪音:数千行 PASSED、弃用警告、锁文件差异。上下文被填满,压缩更早到来,Claude 忘记了你在开始时说的话。
Context Diet 在 Claude 读取每个大型输出之前对其进行裁剪:
- 测试和构建(pytest、jest、go test、cargo、tsc……)→ 仅保留失败和摘要
- JSON → 其结构
- 差异 → 不含锁文件变动
- 日志 → 带上下文的错误
完整输出始终保存到文件,因此 Claude 在需要更多信息时可以读取它。额外好处:当测试运行失败时,Claude Code 会截断输出的末尾,而失败恰恰就在那里。Context Diet 将它们恢复。
在 18 次代理运行中测试:修复了相同的错误,工具调用从 8 次减少到 6 次。
安装:
/plugin marketplace add drkokorev/context-diet /plugin install context-diet@context-diet
https://github.com/drkokorev/context-diet
安装
安装方法请查看原始来源。
原文 / README
A single test run or build log can dump 30–50k characters into Claude’s context, almost all of it noise: thousands of PASSED lines, deprecation warnings, lockfile diffs. The context fills up, compaction comes sooner, and Claude forgets what you said at the start. Context Diet trims every big output before Claude reads it: tests and builds (pytest, jest, go test, cargo, tsc…) → only the failures and the summary JSON → its structure, diffs → without lockfile churn, logs → errors with context the full output is always saved to a file, so Claude can read it when it needs more Bonus: when a test run fails, Claude Code cuts the end of the output, exactly where the failures are. Context Diet gives them back. Tested on 18 agent runs: same bugs fixed, 6 tool calls instead of 8. /plugin marketplace add drkokorev/context-diet /plugin install context-diet@context-diet https://github.com/drkokorev/context-diet submitted by /u/drkokorev to r/ClaudeCodeMods [link] [comments]
其他同名作品
- Context Diet:一个防止巨大工具输出淹没上下文的 Claude Code 模组drkokorev · ★ 1
