技能 cc-skill-strategic-compact
📦

cc-skill-strategic-compact

安全 📁 文件系统访问

建议战略性上下文压缩时机

长时间的 Claude Code 会话会积累上下文,导致性能随时间下降。此技能识别压缩上下文的最佳时机,同时不干扰工作流程的推进势头。

支持: Claude Codex Code(CC)
🥉 74 青铜
1

下载技能 ZIP

2

在 Claude 中上传

前往 设置 → 功能 → 技能 → 上传技能

3

开启并开始使用

测试它

正在使用“cc-skill-strategic-compact”。 Tool call threshold reached (50 calls)

预期结果:

[StrategicCompact] 50 tool calls reached - consider /compact if transitioning phases

正在使用“cc-skill-strategic-compact”。 Periodic checkpoint at 75 tool calls

预期结果:

[StrategicCompact] 75 tool calls - good checkpoint for /compact if context is stale

正在使用“cc-skill-strategic-compact”。 User runs /compact after seeing suggestion

预期结果:

Conversation summary created with key decisions and code changes preserved. Context reduced from 50 messages to 12 summary points.

安全审计

安全
v1 • 2/25/2026

All static analysis findings are false positives. The skill is a benign shell script that tracks tool call counts in a temp file and outputs suggestions to stderr. No network access, no credential handling, no command injection vectors. The temp file usage is for local state tracking only.

2
已扫描文件
69
分析行数
2
发现项
1
审计总数
低风险问题 (1)
Temp directory file creation
Script creates a counter file in /tmp directory for tracking tool call counts across hook invocations

风险因素

📁 文件系统访问 (1)
审计者: claude

质量评分

38
架构
100
可维护性
87
内容
50
社区
100
安全
91
规范符合性

你能构建什么

扩展开发会话

从事复杂多文件重构任务的开发人员在完成探索阶段并进入实现阶段之前,会收到及时的上下文压缩提醒

从研究到实现的过渡

数据科学家和分析师在从数据探索过渡到代码生成时会收到检查点通知,确保相关上下文得到保留

多任务工作流管理

处理多个并发任务的项目经理会收到定期建议,在开始新里程碑之前压缩已完成的工作

试试这些提示

基本压缩请求
Review our conversation and create a concise summary of key decisions, code changes, and open questions. Preserve only what's needed to continue the current task.
阶段过渡摘要
We are transitioning from exploration to implementation. Summarize the requirements and constraints discovered, then reset context for the implementation phase.
里程碑完成归档
Complete the current milestone and create an archival summary. Document what was accomplished, files modified, and any follow-up actions. Then compact to prepare for the next milestone.
上下文健康检查
Analyze our current conversation context. Identify redundant exchanges, resolved questions, and outdated information that can be safely removed while maintaining task continuity.

最佳实践

  • 在完成逻辑工作流阶段后压缩上下文,而不是在活动问题解决过程中
  • 审查压缩建议并在压缩前手动验证重要上下文已保留
  • 设置 COMPACT_THRESHOLD 环境变量以匹配您的典型会话复杂度和注意力持续时间

避免

  • 不要在调试会话中途压缩上下文,因为完整历史记录至关重要
  • 避免将阈值设置得太低(低于 25),这会导致过早的压缩建议
  • 不要仅依赖自动建议 - 在压缩之前要根据任务重要性进行判断

常见问题

此技能如何追踪工具调用次数?
它在 /tmp 目录中维护一个简单的计数器文件。每次 hook 调用都会递增计数器,使脚本能够在整个会话中追踪累积的工具使用情况。
此技能会自动压缩我的上下文吗?
不会,它只通过向 stderr 写入来提供建议。您必须在收到建议时手动使用 /compact 命令或自己总结上下文来触发压缩。
我可以自定义建议出现的时机吗?
是的,将 COMPACT_THRESHOLD 环境变量设置为您首选的工具调用次数(默认是 50)。超过阈值后,建议会每 25 次工具调用出现一次。
如果我删除了临时计数器文件会发生什么?
脚本将创建一个新文件并从 1 开始计数。您将根据新计数收到建议,实际上重置了当前会话的追踪。
此技能用于敏感项目安全吗?
是的。此脚本没有网络访问权限,不读取项目文件,只追踪整数计数。临时文件只包含一个数字,没有任何项目特定数据。
我需要手动配置 hooks 吗?
是的。将脚本注释中显示的 hook 配置添加到您的 ~/.claude/settings.json 文件中,以在 Edit 或 Write 工具调用之前启用自动建议。