with one click
strategic-compact
建议在逻辑间隔处手动压缩上下文,以在任务阶段中保留上下文,而非任意的自动压缩。
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Menu
建议在逻辑间隔处手动压缩上下文,以在任务阶段中保留上下文,而非任意的自动压缩。
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Based on SOC occupation classification
Instinct-based learning system that observes sessions via hooks, creates atomic instincts with confidence scoring, and evolves them into skills/commands/agents. v2.1 adds project-scoped instincts to prevent cross-project contamination.
基于本能的学习系统,通过钩子观察会话,创建带置信度评分的原子本能,并将其进化为技能/命令/代理。v2.1版本增加了项目范围的本能,以防止跨项目污染。
任意の自動コンパクションではなく、タスクフェーズを通じてコンテキストを保持するための論理的な間隔での手動コンパクションを提案します。
임의의 자동 컴팩션 대신 논리적 간격에서 수동 컨텍스트 압축을 제안하여 작업 단계를 통해 컨텍스트를 보존합니다.
Suggests manual context compaction at logical intervals to preserve context through task phases rather than arbitrary auto-compaction.
Suggests manual context compaction at logical intervals to preserve context through task phases rather than arbitrary auto-compaction.
| name | strategic-compact |
| description | 建议在逻辑间隔处手动压缩上下文,以在任务阶段中保留上下文,而非任意的自动压缩。 |
| origin | ECC |
建议在你的工作流程中的战略节点手动执行 /compact,而不是依赖任意的自动精简。
自动精简会在任意时间点触发:
在逻辑边界进行战略精简:
suggest-compact.js 脚本在 PreToolUse (Edit/Write) 时运行,并且:
作为插件安装? 无需任何设置。插件的 hooks/hooks.json 已经注册了 suggest-compact.js(钩子 ID pre:edit-write:suggest-compact,在 standard 和 strict 钩子配置档中生效)。不要把下面的代码块复制到 ~/.claude/settings.json — 插件安装中不存在 ~/.claude/scripts/,并且重复注册插件钩子会导致双重执行。
如果是手动安装(./install.sh),添加到你的 ~/.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 Focus on implementing auth middleware next不在会话开始时加载完整的技能内容,而是使用一个将关键词映射到技能路径的触发表。技能仅在触发时加载,可将基线上下文减少 50% 以上:
| 触发词 | 技能 | 加载时机 |
|---|---|---|
| "test", "tdd", "coverage" | tdd-workflow | 用户提及测试时 |
| "security", "auth", "xss" | security-review | 涉及安全相关工作时 |
| "deploy", "ci/cd" | deployment-patterns | 涉及部署上下文时 |
监控哪些内容正在消耗你的上下文窗口:
常见的重复上下文来源:
~/.claude/rules/ 和项目 .claude/rules/ 中token-optimizer MCP — 通过内容去重实现 95% 以上的自动令牌减少context-mode — 上下文虚拟化(已演示从 315KB 减少到 5.4KB)continuous-learning 技能 — 在会话结束前提取模式