Suggests manual /compact snapshots at logical task boundaries to preserve context across research, planning, implementation, and testing phases. Includes a hook-based tool call tracker and a compression decision guide.
How this skill is triggered — by the user, by Claude, or both
Slash command
/everything-claude-code:strategic-compactThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
建议在工作流中的战略点手动 `/compact`,而不是依赖任意的自动压缩。
建议在工作流中的战略点手动 /compact,而不是依赖任意的自动压缩。
自动压缩在任意点触发:
在逻辑边界进行策略压缩:
suggest-compact.js 脚本在 PreToolUse(Edit/Write)上运行:
添加到你的 ~/.claude/settings.json:
{
"hooks": {
"PreToolUse": [
{
"matcher": "Edit",
"hooks": [{ "type": "command", "command": "node ~/.claude/scripts/hooks/suggest-compact.js" }]
},
{
"matcher": "Write",
"hooks": [{ "type": "command", "command": "node ~/.claude/scripts/hooks/suggest-compact.js" }]
}
]
}
}
环境变量:
COMPACT_THRESHOLD — 首次建议前的工具调用次数(默认:50)使用此表决定何时压缩:
| 阶段转换 | 压缩? | 原因 |
|---|---|---|
| 研究 → 规划 | 是 | 研究上下文体积大;规划是提炼后的输出 |
| 规划 → 实现 | 是 | 规划在 TodoWrite 或文件中;释放上下文给代码 |
| 实现 → 测试 | 可能 | 如果测试引用近期代码则保留;如果切换焦点则压缩 |
| 调试 → 下一个功能 | 是 | 调试痕迹会污染不相关工作的上下文 |
| 实现中途 | 否 | 丢失变量名、文件路径和部分状态的代价很高 |
| 失败的方法之后 | 是 | 在尝试新方法之前清除死胡同推理 |
了解什么会持续存在有助于你自信地压缩:
| 保留 | 丢失 |
|---|---|
| CLAUDE.md 指令 | 中间推理和分析 |
| TodoWrite 任务列表 | 之前读取的文件内容 |
记忆文件(~/.claude/memory/) | 多步对话上下文 |
| Git 状态(提交、分支) | 工具调用历史和计数 |
| 磁盘上的文件 | 口头表达的细微用户偏好 |
/compact — 添加自定义消息:/compact 接下来专注于实现认证中间件不是在会话开始时加载完整的 skill 内容,而是使用将关键字映射到 skill 路径的触发表。Skills 仅在触发时加载,将基线上下文减少 50%+:
| 触发词 | Skill | 加载时机 |
|---|---|---|
| "test"、"tdd"、"coverage" | tdd-workflow | 用户提到测试 |
| "security"、"auth"、"xss" | security-review | 安全相关工作 |
| "deploy"、"ci/cd" | deployment-patterns | 部署上下文 |
监控什么在消耗你的上下文窗口:
重复上下文的常见来源:
~/.claude/rules/ 和项目 .claude/rules/ 中的相同规则token-optimizer MCP — 通过内容去重实现 95%+ 的 token 减少context-mode — 上下文虚拟化(演示从 315KB 到 5.4KB)continuous-learning skill — 在会话结束前提取模式npx claudepluginhub aaione/everything-claude-code-zhSuggests manual /compact at tool call thresholds during long, multi-phase Claude Code sessions to preserve context across task phases over arbitrary auto-compaction.
Suggests manual /compact at logical intervals (e.g., after research, before implementation) to preserve context through task phases. Activates when context pressure builds or after milestones, using a hook script to track tool calls.
Suggests manual context compaction at logical intervals via a pre-tool hook, preserving context through task phases rather than relying on arbitrary auto-compaction.