Skip to content
cccskills
FreePublished on GitHub

strategic-compact

Use this skill to decide when to manually compact a long agent session, such as after research or a milestone. A hook can count tool calls and suggest `/compact` at a configurable threshold, helping manage context between task stages.

OriginalShow the original description

建议在逻辑间隔处手动压缩上下文,以在任务阶段中保留上下文,而非任意的自动压缩。

Run score Not tested

See how to install

Good for

  • Compacting context after research and before planning
  • Starting a fresh stage after a milestone
  • Deciding whether to compact before switching tasks
  • Setting a reminder threshold for tool calls

Files included (1)

  • SKILL.md4.5 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

战略精简技能

建议在你的工作流程中的战略节点手动执行 /compact,而不是依赖任意的自动精简。

何时激活

  • 运行长时间会话,接近上下文限制时(200K+ tokens)
  • 处理多阶段任务时(研究 → 规划 → 实施 → 测试)
  • 在同一会话中切换不相关的任务时
  • 完成一个主要里程碑并开始新工作时
  • 当响应变慢或连贯性下降时(上下文压力)

为何采用战略精简?

自动精简会在任意时间点触发:

  • 通常在任务中途,丢失重要上下文
  • 无法感知逻辑任务边界
  • 可能中断复杂的多步骤操作

在逻辑边界进行战略精简:

  • 探索之后,执行之前 — 压缩研究上下文,保留实施计划
  • 完成里程碑之后 — 为下一阶段重新开始
  • 在主要上下文切换之前 — 在开始不同任务前清理探索上下文

工作原理

suggest-compact.js 脚本在 PreToolUse (Edit/Write) 时运行,并且:

  1. 跟踪工具调用 — 统计会话中的工具调用次数
  2. 阈值检测 — 在可配置的阈值处建议压缩(默认:50次调用)
  3. 定期提醒 — 达到阈值后,每25次调用提醒一次

钩子设置

添加到你的 ~/.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 或文件中;释放上下文以进行编码
实施 → 测试可能如果测试引用最近的代码则保留;如果要切换焦点则压缩
调试 → 下一项功能是调试痕迹会污染不相关工作的上下文
实施过程中否丢失变量名、文件路径和部分状态代价高昂
尝试失败的方法之后是在尝试新方法之前,清理掉无效的推理过程

压缩后保留的内容

了解哪些内容会保留有助于您自信地进行压缩:

保留的内容丢失的内容
CLAUDE.md 指令中间的推理和分析
TodoWrite 任务列表您之前读取过的文件内容
记忆文件 (~/.claude/memory/)多轮对话的上下文
Git 状态(提交、分支)工具调用历史和计数
磁盘上的文件口头陈述的细微用户偏好

最佳实践

  1. 规划后压缩 — 一旦计划在 TodoWrite 中最终确定,就压缩以重新开始
  2. 调试后压缩 — 在继续之前,清理错误解决上下文
  3. 不要在实施过程中压缩 — 为相关更改保留上下文
  4. 阅读建议 — 钩子告诉您何时,您决定是否
  5. 压缩前写入 — 在压缩前将重要上下文保存到文件或记忆中
  6. 使用带摘要的 /compact — 添加自定义消息:/compact Focus on implementing auth middleware next

相关

  • 长篇指南 — Token 优化部分
  • 记忆持久化钩子 — 用于在压缩后保留状态
  • continuous-learning 技能 — 在会话结束前提取模式

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

api-design

FreeSummary

Use this skill to design or review REST APIs. It covers resource URLs, HTTP methods and status codes, pagination, filtering, sorting, error responses, authentication, rate limits, and versioning, with patterns for consistent endpoint contracts.

  • Designing a new REST endpoint
  • Reviewing an existing API contract
  • Choosing pagination and filtering patterns
xu-xiang/everything-claude-code-zh2KUpdated Mar 5, 2026

api-design

FreeSummary

Use this skill to design or review REST APIs, including resource URLs, HTTP methods and status codes, pagination, filtering, errors, versioning, and rate limits. It helps make endpoint behavior and response formats consistent for clients and developers.

  • Designing endpoints for a new REST API
  • Reviewing an API contract
  • Adding pagination, filtering, or sorting
xu-xiang/everything-claude-code-zh2KUpdated Mar 5, 2026

article-writing

FreeSummary

Draft or revise long-form pieces such as articles, guides, tutorials, and newsletters. The skill helps shape a clear structure, match a supplied writing sample or brand guide, and ground claims in provided sources without inventing biographical facts, company metrics, or testimonials.

  • Drafting a blog post from notes or research
  • Matching a supplied brand voice
  • Restructuring a long draft for clarity
xu-xiang/everything-claude-code-zh2KUpdated Mar 5, 2026

article-writing

FreeSummary

Draft or refine long-form writing such as articles, guides, blog posts, tutorials, and newsletters. It can follow supplied writing samples or brand guidance, organize sections around a clear purpose, and keep claims grounded in the provided sources.

  • Draft a blog post from notes or research
  • Match an article to supplied writing samples
  • Turn a transcript into a polished guide
xu-xiang/everything-claude-code-zh2KUpdated Mar 5, 2026

article-writing

FreeSummary

Use this skill to draft or revise long-form content such as articles, guides, tutorials, and newsletters. It can shape structure and pacing, turn notes or research into polished copy, and match a supplied voice sample or brand guide while checking claims against sources.

  • Drafting a blog post or newsletter
  • Turning notes or research into an article
  • Matching a supplied writing sample
xu-xiang/everything-claude-code-zh2KUpdated Mar 5, 2026

article-writing

FreeSummary

Draft or refine long-form articles, guides, tutorials, and newsletters using a supplied style reference or a clear, practical default voice. The skill helps shape structure, improve pacing, and check claims against source material without inventing credentials or evidence.

  • Turning research notes into a polished article
  • Matching a founder’s or brand’s writing voice
  • Improving the structure of a long draft
xu-xiang/everything-claude-code-zh2KUpdated Mar 5, 2026

See all skills by xu-xiang

Report a problem with this skill