[开源][ClaudeCode] 通过 SubAgent 实现 Augment Context Engine! 节约 83%的上下文!

7 天前
 pDJJq

https://github.com/TokenRollAI/cc-plugin

核心实现:

  1. Scout Agnet (做大量的读取, 并且最终组织为一个精简高价值的输出): https://github.com/TokenRollAI/cc-plugin/blob/main/agents/scout.md
  2. Scout Command(强化 Agent 的调用/并行调用): https://github.com/TokenRollAI/cc-plugin/blob/main/commands/withScout.md

原理

https://docs.claude.com/en/docs/claude-code/sub-agents

sub-agent 的上下文非常独立, 不影响主 agent 的进行. 非常适合做大量的 读 -> 总结 的操作.

正如帖子所说: https://linux.do/t/topic/1031049

claude code 的核心问题是: 用超量的上下文解决问题, 在小规模问题上良好, 在中大型项目上表现容易爆上下文.

或者说: 全量读带来的冗余上下文.

注意: 这里的冗余指的是对主 Agent 的上下文冗余.

这件事情非常适合放在 subagent 里解决!

效果如下:

效果

同样的问题:项目中的 Operator 有什么作用? 数据存储和流转是怎么实现的?

使用 subagent: 29K

> /context
  ⎿  Context Usage
     ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛀ ⛁ ⛀   claude-sonnet-4-5-20250929 · 17k/200k tokens (9%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ System prompt: 2.3k tokens (1.2%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ System tools: 12.1k tokens (6.0%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ Custom agents: 120 tokens (0.1%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ Memory files: 2.6k tokens (1.3%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ Messages: 8 tokens (0.0%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛶ Free space: 183k (91.4%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶

未使用 subagent: 83K

> /context
  ⎿  Context Usage
     ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛀ ⛁ ⛁   claude-sonnet-4-5-20250929 · 83k/200k tokens (42%)
     ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁
     ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁   ⛁ System prompt: 2.3k tokens (1.2%)
     ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁   ⛁ System tools: 12.1k tokens (6.0%)
     ⛁ ⛁ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ Custom agents: 120 tokens (0.1%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ Memory files: 2.6k tokens (1.3%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ Messages: 66.0k tokens (33.0%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛶ Free space: 117k (58.5%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶

结论

去除掉初始 context 占用: 17K

subagent 方案增加主 agent context: 12K 原始方案增加 context: 70K

节约上下文: 83% !

TODO

  1. 基于 LSP 的 symbol 粒度信息获取
  2. 更好的任务划分, 增加并行度.

可以自行体验下, 目前看在我的工作项目中效果不错.

点点 Star!

327 次点击
所在节点    Claude
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1164861

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX