strategic-compact
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseStrategic Compact Skill
策略性压缩Skill
Suggests manual at strategic points in your workflow rather than relying on arbitrary auto-compaction.
/compact建议在工作流中的关键节点手动执行命令,而非依赖任意触发的自动压缩。
/compactWhy Strategic Compaction?
为什么选择策略性压缩?
Auto-compaction triggers at arbitrary points:
- Often mid-task, losing important context
- No awareness of logical task boundaries
- Can interrupt complex multi-step operations
Strategic compaction at logical boundaries:
- After exploration, before execution - Compact research context, keep implementation plan
- After completing a milestone - Fresh start for next phase
- Before major context shifts - Clear exploration context before different task
自动压缩会在任意节点触发:
- 通常在任务进行到一半时触发,丢失重要上下文
- 无法识别合理的任务边界
- 可能会中断复杂的多步骤操作
在合理边界进行策略性压缩:
- 探索完成后、执行前 - 压缩研究上下文,保留实施计划
- 完成里程碑后 - 为下一阶段重新开始
- 在重大上下文切换前 - 在开始不同任务前清理探索上下文
How It Works
工作原理
The script runs on PreToolUse (Edit/Write) and:
suggest-compact.sh- Tracks tool calls - Counts tool invocations in session
- Threshold detection - Suggests at configurable threshold (default: 50 calls)
- Periodic reminders - Reminds every 25 calls after threshold
suggest-compact.sh- 跟踪工具调用 - 统计会话中的工具调用次数
- 阈值检测 - 在可配置的阈值(默认:50次调用)时给出建议
- 定期提醒 - 达到阈值后每25次调用提醒一次
Hook Setup
钩子设置
Add to your :
~/.claude/settings.jsonjson
{
"hooks": {
"PreToolUse": [{
"matcher": "tool == \"Edit\" || tool == \"Write\"",
"hooks": [{
"type": "command",
"command": "~/.claude/skills/strategic-compact/suggest-compact.sh"
}]
}]
}
}添加到你的中:
~/.claude/settings.jsonjson
{
"hooks": {
"PreToolUse": [{
"matcher": "tool == \"Edit\" || tool == \"Write\"",
"hooks": [{
"type": "command",
"command": "~/.claude/skills/strategic-compact/suggest-compact.sh"
}]
}]
}
}Configuration
配置
Environment variables:
- - Tool calls before first suggestion (default: 50)
COMPACT_THRESHOLD
环境变量:
- - 首次给出建议前的工具调用次数(默认:50次)
COMPACT_THRESHOLD
Best Practices
最佳实践
- Compact after planning - Once plan is finalized, compact to start fresh
- Compact after debugging - Clear error-resolution context before continuing
- Don't compact mid-implementation - Preserve context for related changes
- Read the suggestion - The hook tells you when, you decide if
- 规划完成后压缩 - 计划确定后,进行压缩以重新开始
- 调试完成后压缩 - 继续之前清理错误解决上下文
- 不要在实施过程中压缩 - 保留上下文以进行相关更改
- 查看建议 - 钩子会告诉你何时压缩,由你决定是否压缩
Related
相关内容
- The Longform Guide - Token optimization section
- Memory persistence hooks - For state that survives compaction
- 长篇内容指南 - 令牌优化章节
- 内存持久化钩子 - 用于在压缩后保留状态