建议在逻辑间隔进行手动上下文压缩(Context Compaction),以便在任务阶段中保留上下文,而不是依赖任意的自动压缩。
51
56%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Passed
No findings from the security scan
Fix and improve this skill with Tessl
tessl review fix ./.agents/skills/strategic-compact/SKILL.md建议在工作流的策略点手动执行 /compact 命令,而不是依赖任意的自动压缩(Auto-compaction)。
自动压缩在任意点触发:
逻辑边界处的策略性压缩:
suggest-compact.js 脚本在 PreToolUse(Edit/Write)钩子(Hook)上运行,并且:
添加到你的 ~/.claude/settings.json 中:
{
"hooks": {
"PreToolUse": [
{
"matcher": "Edit",
"hooks": [{ "type": "command", "command": "node ~/.claude/skills/strategic-compact/suggest-compact.js" }]
},
{
"matcher": "Write",
"hooks": [{ "type": "command", "command": "node ~/.claude/skills/strategic-compact/suggest-compact.js" }]
}
]
}
}环境变量:
COMPACT_THRESHOLD —— 第一次建议前的工具调用次数(默认:50)使用下表来决定何时压缩:
| 阶段转换 | 是否压缩? | 原因 |
|---|---|---|
| 研究 → 规划 | 是 | 研究上下文很臃肿;方案是提炼后的产出 |
| 规划 → 实现 | 是 | 方案已在 TodoWrite 或文件中;为代码腾出上下文空间 |
| 实现 → 测试 | 可能 | 如果测试引用了近期代码则保留;如果切换关注点则压缩 |
| 调试 → 下一功能 | 是 | 调试追踪(Debug traces)会污染不相关工作的上下文 |
| 实现中 | 否 | 丢失变量名、文件路径和部分状态的代价很高 |
| 方案失败后 | 是 | 在尝试新方案前清除死胡同式的推理 |
了解哪些内容会持久化,有助于你充满信心地进行压缩:
| 保留 | 丢失 |
|---|---|
CLAUDE.md 指令 | 中间推理和分析 |
TodoWrite 任务列表 | 之前读取过的文件内容 |
记忆文件(~/.claude/memory/) | 多步骤对话上下文 |
| Git 状态(提交、分支) | 工具调用历史和计数 |
| 磁盘上的文件 | 口头陈述的细微用户偏好 |
TodoWrite 中确定,就进行压缩以全新开始/compact 下一步重点实现认证中间件continuous-learning 技能 —— 在会话结束前提取模式dfbf946
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.