strategic-compact by affaan-m/everything-claude-code
npx skills add https://github.com/affaan-m/everything-claude-code --skill strategic-compact建议在工作流的关键节点手动使用 /compact 命令,而非依赖随机的自动压缩。
自动压缩会在任意时间点触发:
在逻辑边界进行策略性压缩:
suggest-compact.js 脚本在 PreToolUse(编辑/写入)时运行,并执行以下操作:
添加到你的 ~/.claude/settings.json 文件中:
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
{
"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 或文件中;为代码释放上下文 |
| 实施 → 测试 | 可能 | 如果测试引用近期代码则保留;如果切换焦点则压缩 |
| 调试 → 下一个功能 | 是 | 调试痕迹会污染不相关工作的上下文 |
| 实施过程中 | 否 | 丢失变量名、文件路径和部分状态代价高昂 |
| 尝试失败的方法后 | 是 | 在尝试新方法前清理死胡同的推理过程 |
了解哪些内容会保留有助于你自信地进行压缩:
| 保留的内容 | 丢失的内容 |
|---|---|
| CLAUDE.md 指令 | 中间推理和分析过程 |
| TodoWrite 任务列表 | 你之前读取的文件内容 |
记忆文件(~/.claude/memory/) | 多轮对话上下文 |
| Git 状态(提交、分支) | 工具调用历史和计数 |
| 磁盘上的文件 | 口头陈述的细微用户偏好 |
/compact 并附带摘要 — 添加自定义消息:/compact 接下来专注于实施认证中间件continuous-learning 技能 — 在会话结束前提取模式每周安装量
1.0K
代码仓库
GitHub 星标数
72.1K
首次出现
Jan 22, 2026
安全审计
安装于
opencode829
codex796
gemini-cli781
claude-code778
github-copilot700
cursor695
Suggests manual /compact at strategic points in your workflow rather than relying on arbitrary auto-compaction.
Auto-compaction triggers at arbitrary points:
Strategic compaction at logical boundaries:
The suggest-compact.js script runs on PreToolUse (Edit/Write) and:
Add to your ~/.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" }]
}
]
}
}
Environment variables:
COMPACT_THRESHOLD — Tool calls before first suggestion (default: 50)Use this table to decide when to compact:
| Phase Transition | Compact? | Why |
|---|---|---|
| Research → Planning | Yes | Research context is bulky; plan is the distilled output |
| Planning → Implementation | Yes | Plan is in TodoWrite or a file; free up context for code |
| Implementation → Testing | Maybe | Keep if tests reference recent code; compact if switching focus |
| Debugging → Next feature | Yes | Debug traces pollute context for unrelated work |
| Mid-implementation | No | Losing variable names, file paths, and partial state is costly |
| After a failed approach | Yes | Clear the dead-end reasoning before trying a new approach |
Understanding what persists helps you compact with confidence:
| Persists | Lost |
|---|---|
| CLAUDE.md instructions | Intermediate reasoning and analysis |
| TodoWrite task list | File contents you previously read |
Memory files (~/.claude/memory/) | Multi-step conversation context |
| Git state (commits, branches) | Tool call history and counts |
| Files on disk | Nuanced user preferences stated verbally |
/compact with a summary — Add a custom message: /compact Focus on implementing auth middleware nextcontinuous-learning skill — Extracts patterns before session endsWeekly Installs
1.0K
Repository
GitHub Stars
72.1K
First Seen
Jan 22, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode829
codex796
gemini-cli781
claude-code778
github-copilot700
cursor695
97,600 周安装