context-compressor
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseContext Compressor Skill
Context Compressor Skill
<identity>
Context Compressor Skill - Techniques for reducing token usage while preserving decision-critical information. Helps agents work efficiently within context limits.
</identity>
<capabilities>
- Compressing conversation history
- Summarizing code and documentation
- Extracting key decisions and context
- Creating efficient memory snapshots
- Reducing redundancy in context
</capabilities>
<instructions>
<execution_process>
<identity>
Context Compressor Skill - 用于在保留决策关键信息的同时降低Token使用量的技巧,帮助Agent在上下文限制内高效工作。
</identity>
<capabilities>
- 压缩对话历史
- 总结代码与文档
- 提取关键决策与上下文信息
- 创建高效的内存快照
- 减少上下文中的冗余内容
</capabilities>
<instructions>
<execution_process>
Step 1: Identify Compressible Content
步骤1:识别可压缩内容
Content types that can be compressed:
| Type | Compression Strategy |
|---|---|
| Code | Keep signatures, summarize implementations |
| Conversations | Extract decisions, drop small talk |
| Documentation | Keep headings and key points |
| Errors | Keep message and location, drop stack frames |
| Logs | Keep patterns, drop repetitions |
可压缩的内容类型:
| 类型 | 压缩策略 |
|---|---|
| 代码 | 保留签名,总结实现逻辑 |
| 对话内容 | 提取决策信息,剔除闲聊内容 |
| 文档 | 保留标题与核心要点 |
| 错误信息 | 保留错误消息与位置,剔除调用栈帧 |
| 日志 | 保留模式规律,剔除重复内容 |
Step 2: Apply Compression Techniques
步骤2:应用压缩技巧
Technique 1: Decision Extraction
Before:
User: Should we use Redis or Memcached?
Assistant: Let me analyze both options...
[500 words of analysis]
Recommendation: Redis for pub/sub support.
User: Ok let's use Redis.After:
Decision: Use Redis (chosen for pub/sub support)Technique 2: Code Summarization
Before:
javascript
// 100 lines of UserService implementationAfter:
UserService: CRUD operations for users
- Methods: create, read, update, delete, findByEmail
- Dependencies: db, validator, logger
- Location: src/services/user.jsTechnique 3: Error Compression
Before:
Error: Cannot read property 'id' of undefined
at UserController.getUser (src/controllers/user.js:45:23)
at Layer.handle [as handle_request] (node_modules/express/lib/router/layer.js:95:5)
... 20 more stack framesAfter:
Error: Cannot read 'id' of undefined @ src/controllers/user.js:45
Cause: User object is null when accessing .id技巧1:决策提取
压缩前:
User: Should we use Redis or Memcached?
Assistant: Let me analyze both options...
[500 words of analysis]
Recommendation: Redis for pub/sub support.
User: Ok let's use Redis.压缩后:
Decision: Use Redis (chosen for pub/sub support)技巧2:代码总结
压缩前:
javascript
// 100 lines of UserService implementation压缩后:
UserService: 用户相关CRUD操作
- 方法:create、read、update、delete、findByEmail
- 依赖:db、validator、logger
- 位置:src/services/user.js技巧3:错误信息压缩
压缩前:
Error: Cannot read property 'id' of undefined
at UserController.getUser (src/controllers/user.js:45:23)
at Layer.handle [as handle_request] (node_modules/express/lib/router/layer.js:95:5)
... 20 more stack frames压缩后:
Error: Cannot read 'id' of undefined @ src/controllers/user.js:45
原因:访问.id时User对象为nullStep 3: Structure Compressed Output
步骤3:结构化压缩输出
Use consistent formats:
markdown
undefined使用统一格式:
markdown
undefinedSession Summary
会话总结
Decisions Made
已做出的决策
- [D1] Use Redis for caching
- [D2] JWT for authentication
- [D1] 使用Redis作为缓存
- [D2] 使用JWT进行身份验证
Files Modified
修改的文件
- src/auth/jwt.js (new)
- src/config/redis.js (updated)
- src/auth/jwt.js(新增)
- src/config/redis.js(更新)
Open Items
待办事项
- Add rate limiting
- Write tests for JWT
undefined- 添加限流机制
- 为JWT编写测试用例
undefinedStep 4: Validate Compression
步骤4:验证压缩效果
Ensure critical info preserved:
- All decisions captured
- Key file locations retained
- Error causes documented
- Next steps clear
</execution_process>
<best_practices>
- Preserve Decisions: Never lose decision rationale
- Keep Locations: File paths and line numbers are critical
- Summarize, Don't Delete: Transform verbose content
- Use References: Point to files instead of including content
- Test Recovery: Can you continue work from compressed context?
</best_practices>
</instructions>
<examples>
<usage_example>
**Compression Request**:
Compress the last 10 messages for context handoffExample Response:
markdown
undefined确保关键信息已保留:
- 所有决策已捕获
- 关键文件位置已保留
- 错误原因已记录
- 后续步骤清晰明确
</execution_process>
<best_practices>
- 保留决策信息:绝不能丢失决策的依据
- 保留位置信息:文件路径与行号至关重要
- 总结而非删除:将冗长内容进行转化
- 使用引用:指向文件而非直接包含内容
- 测试可恢复性:能否基于压缩后的上下文继续开展工作?
</best_practices>
</instructions>
<examples>
<usage_example>
**压缩请求**:
Compress the last 10 messages for context handoff示例响应:
markdown
undefinedContext Summary (compressed from 10 messages)
上下文总结(由10条消息压缩而来)
Task
任务
Implementing user authentication with JWT
基于JWT实现用户身份验证
Progress
进度
- Created JWT utility (src/auth/jwt.js)
- Added login endpoint (src/routes/auth.js)
- Tests failing - mock issue
- 已创建JWT工具类(src/auth/jwt.js)
- 已添加登录接口(src/routes/auth.js)
- 测试失败 - 模拟数据存在问题
Key Decisions
关键决策
- Using RS256 for JWT signing (security over performance)
- 1-hour token expiry with refresh tokens
- 使用RS256进行JWT签名(优先考虑安全性而非性能)
- Token有效期为1小时,支持刷新Token
Current Issue
当前问题
Jest mock for jwt.sign not working
Location: src/auth/tests/jwt.test.js:23
Jest对jwt.sign的模拟不生效
位置:src/auth/tests/jwt.test.js:23
Next Steps
后续步骤
- Fix JWT mock
- Add refresh token endpoint
</usage_example>
</examples>- 修复JWT模拟问题
- 添加刷新Token接口
</usage_example>
</examples>Rules
规则
- Never lose decision rationale
- Always include file locations
- Test that work can continue from compressed context
- 绝不能丢失决策的依据
- 始终包含文件位置信息
- 验证能否基于压缩后的上下文继续开展工作
Workflow Integration
工作流集成
This skill supports multi-agent orchestration by enabling efficient context management:
Router Decision:
.claude/workflows/core/router-decision.md- Router spawns agents that use this skill for context-efficient handoffs
- Used in long-running sessions to maintain continuity
Artifact Lifecycle:
.claude/workflows/core/skill-lifecycle.md- Compression patterns evolve with framework changes
- Session summaries feed into memory protocol
Related Workflows:
- skill for complete handoff protocol
session-handoff - skill for multi-agent context sharing
swarm-coordination
该Skill通过高效的上下文管理支持多Agent编排:
路由决策:
.claude/workflows/core/router-decision.md- 路由模块会生成使用该Skill的Agent,以实现高效的上下文交接
- 用于长时运行会话,维持工作连续性
工件生命周期:
.claude/workflows/core/skill-lifecycle.md- 压缩模式会随框架更新而演进
- 会话总结会同步到内存协议中
相关工作流:
- Skill:用于完整的上下文交接协议
session-handoff - Skill:用于多Agent上下文共享
swarm-coordination
Memory Protocol (MANDATORY)
内存协议(强制要求)
Before starting:
bash
cat .claude/context/memory/learnings.mdAfter completing:
- New pattern ->
.claude/context/memory/learnings.md - Issue found ->
.claude/context/memory/issues.md - Decision made ->
.claude/context/memory/decisions.md
ASSUME INTERRUPTION: Your context may reset. If it's not in memory, it didn't happen.
开始前:
bash
cat .claude/context/memory/learnings.md完成后:
- 新的模式 ->
.claude/context/memory/learnings.md - 发现的问题 ->
.claude/context/memory/issues.md - 做出的决策 ->
.claude/context/memory/decisions.md
假设可能出现中断:你的上下文可能会重置。如果信息未存入内存,则视为未发生。