Context Optimizer — Token Economy Protocol
Version: 1.1.0 | Author: Shadows Company | License: MIT
WHEN TO TRIGGER
- - Context window approaching capacity (>70% usage)
- Agent responses becoming slower or less coherent
- User says "optimize context", "compact", "reduce tokens"
- Working with very large codebases
- Multi-file operations causing context bloat
WHEN NOT TO TRIGGER
- - Short conversations with plenty of context remaining
- Simple single-file operations
PREREQUISITES
No binaries required. This is a pure reasoning skill about optimizing context window usage. It provides strategies and patterns — it does not execute commands or access external systems.
PRINCIPLES
1. Reference Over Inline
Instead of reading entire files into context, reference them:
- - "The auth module at
src/auth/index.ts handles..." instead of pasting 500 lines - Read only the specific functions/sections needed
- Use line ranges:
Read file.py lines 45-80 instead of the whole file
2. DRY Prompts — Zero Duplication
- - Never repeat information already in system context
- Don't re-describe tools you already know about
- Don't re-state project conventions that are in CLAUDE.md/SOUL.md
- If a fact was established earlier, reference it, don't restate it
3. Lazy-Load Strategy
- - Load detailed context only when needed for the current task
- Use subagents/sub-tasks for exploration (protects main context)
- Delegate research to agents, keep main context for execution
4. Smart File Reading
CODEBLOCK0
5. Output Compression
When reporting results:
- - Lead with the answer, not the reasoning
- Skip filler words and unnecessary transitions
- Use tables for comparative data
- Use bullet points for lists, not paragraphs
TECHNIQUES
Technique 1 — Context Audit
Assess current context usage:
- 1. Count how many files have been read in this session
- Identify which file contents are still relevant to the current task
- Determine what information can be summarized instead of kept verbatim
- Flag redundant tool results that repeat already-known information
Technique 2 — Compaction
When context is high:
- 1. Summarize completed work (keep outcomes, drop process details)
- Drop file contents that are no longer needed for the active task
- Keep only active task context in working memory
- Preserve critical state: decisions made, errors encountered, current objectives
Technique 3 — Subagent Delegation
For research-heavy tasks:
- 1. Spawn a subagent for codebase exploration
- Subagent returns only findings (not raw file contents)
- Main context stays clean for implementation
- Multiple subagents can run in parallel for independent queries
Technique 4 — Structured Responses
CODEBLOCK1
ANTI-PATTERNS TO AVOID
| Anti-Pattern | Fix |
|---|
| Reading whole files when you need 10 lines | Use offset + limit |
| Listing all MCP servers |
Agent already knows them |
| Repeating deny rules | Already in settings |
| Describing the OS/environment | Already in system context |
| Re-reading files read earlier | Summarize and reference |
| Multiple searches for one query | One well-crafted search |
| Verbose status updates | Concise milestone updates |
RULES
- 1. Minimum viable context — load only what's needed NOW
- Summarize, don't accumulate — compress completed work
- Delegate exploration — use subagents for research
- Direct answers — skip preamble, lead with the point
- 3-search maximum — never use more than 3 search tools for one query
SECURITY CONSIDERATIONS
This skill is purely advisory — it provides strategies for token optimization. It does not execute commands, read files, make network calls, modify configuration, or store data. Zero risk profile.
- - Commands executed: None
- Data read: None (advisory reasoning only)
- Network access: None
- Persistence: None
- Credentials: None required
- File modification: None
OUTPUT FORMAT
Apply the techniques above inline during agent operation. No separate report is generated — the skill manifests as improved efficiency in the agent's behavior: shorter responses, fewer tool calls, targeted file reads, and minimal context consumption.
Published by Shadows Company — "We work in the shadows to serve the Light."
上下文优化器 — Token经济协议
版本: 1.1.0 | 作者: Shadows Company | 许可证: MIT
触发时机
- - 上下文窗口接近容量上限(使用率>70%)
- 智能体响应变慢或连贯性下降
- 用户说优化上下文、压缩、减少token
- 处理大型代码库时
- 多文件操作导致上下文膨胀
不触发时机
前置条件
无需二进制文件。这是一项关于优化上下文窗口使用的纯推理技能。它提供策略和模式——不执行命令或访问外部系统。
原则
1. 引用优于内联
不要将整个文件读入上下文,而是引用它们:
- - 位于src/auth/index.ts的认证模块处理...而不是粘贴500行代码
- 只读取所需的具体函数/代码段
- 使用行范围:Read file.py lines 45-80而不是整个文件
2. 提示词DRY原则——零重复
- - 绝不重复系统上下文中已有的信息
- 不要重新描述你已经了解的工具
- 不要重复CLAUDE.md/SOUL.md中已有的项目约定
- 如果某个事实之前已确立,引用它,不要复述
3. 懒加载策略
- - 仅在当前任务需要时才加载详细上下文
- 使用子智能体/子任务进行探索(保护主上下文)
- 将研究任务委托给子智能体,主上下文专注于执行
4. 智能文件读取
错误:读取整个2000行文件
正确:读取函数定义所在的150-200行
错误:读取全部15个配置文件
正确:只读取与当前任务相关的配置
错误:在整个代码库中搜索import
正确:在特定目录中搜索特定模式
5. 输出压缩
报告结果时:
- - 先给出答案,再说明推理过程
- 省略填充词和不必要的过渡语
- 对比数据使用表格
- 列表使用要点符号,而非段落
技巧
技巧1 — 上下文审计
评估当前上下文使用情况:
- 1. 统计本次会话中已读取的文件数量
- 识别哪些文件内容仍与当前任务相关
- 确定哪些信息可以总结而非逐字保留
- 标记重复已知信息的冗余工具结果
技巧2 — 压缩
当上下文占用过高时:
- 1. 总结已完成工作(保留结果,丢弃过程细节)
- 删除当前活动任务不再需要的文件内容
- 工作记忆中仅保留当前任务上下文
- 保留关键状态:已做出的决策、遇到的错误、当前目标
技巧3 — 子智能体委托
对于研究密集型任务:
- 1. 生成子智能体进行代码库探索
- 子智能体仅返回发现结果(而非原始文件内容)
- 主上下文保持清洁以专注于实现
- 多个子智能体可并行运行处理独立查询
技巧4 — 结构化响应
错误(100个token):
我查看了文件,经过仔细分析,我认为问题出在认证中间件中,
token验证函数没有正确处理过期token。
正确(30个token):
Bug:认证中间件中的validateToken()未处理过期token。
修复:在第45行添加过期检查。
应避免的反模式
| 反模式 | 修复方案 |
|---|
| 只需10行却读取整个文件 | 使用偏移量+限制 |
| 列出所有MCP服务器 |
智能体已知晓 |
| 重复拒绝规则 | 已在设置中 |
| 描述操作系统/环境 | 已在系统上下文中 |
| 重新读取之前已读过的文件 | 总结并引用 |
| 一个查询多次搜索 | 一次精心设计的搜索 |
| 冗长的状态更新 | 简洁的里程碑更新 |
规则
- 1. 最小可行上下文 — 只加载当前需要的内容
- 总结而非积累 — 压缩已完成的工作
- 委托探索 — 使用子智能体进行研究
- 直接回答 — 跳过开场白,直接切入要点
- 最多3次搜索 — 一个查询最多使用3个搜索工具
安全考量
本技能纯属建议性质——提供token优化策略。不执行命令、不读取文件、不发起网络调用、不修改配置、不存储数据。零风险。
- - 执行的命令:无
- 读取的数据:无(仅提供建议性推理)
- 网络访问:无
- 持久化:无
- 凭证:无需
- 文件修改:无
输出格式
在智能体运行过程中内联应用上述技巧。不生成单独报告——该技能体现为智能体行为效率的提升:更短的响应、更少的工具调用、精准的文件读取、最小的上下文消耗。
由Shadows Company发布——我们在暗处工作,为光明服务。