strategic-compact

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Strategic Compact Skill

策略性压缩Skill

Suggests manual
/compact
at strategic points in your workflow rather than relying on arbitrary auto-compaction.
建议在工作流中的关键节点手动执行
/compact
命令,而非依赖任意触发的自动压缩。

Why Strategic Compaction?

为什么选择策略性压缩?

Auto-compaction triggers at arbitrary points:
  • Often mid-task, losing important context
  • No awareness of logical task boundaries
  • Can interrupt complex multi-step operations
Strategic compaction at logical boundaries:
  • After exploration, before execution - Compact research context, keep implementation plan
  • After completing a milestone - Fresh start for next phase
  • Before major context shifts - Clear exploration context before different task
自动压缩会在任意节点触发:
  • 通常在任务进行到一半时触发,丢失重要上下文
  • 无法识别合理的任务边界
  • 可能会中断复杂的多步骤操作
在合理边界进行策略性压缩:
  • 探索完成后、执行前 - 压缩研究上下文,保留实施计划
  • 完成里程碑后 - 为下一阶段重新开始
  • 在重大上下文切换前 - 在开始不同任务前清理探索上下文

How It Works

工作原理

The
suggest-compact.sh
script runs on PreToolUse (Edit/Write) and:
  1. Tracks tool calls - Counts tool invocations in session
  2. Threshold detection - Suggests at configurable threshold (default: 50 calls)
  3. Periodic reminders - Reminds every 25 calls after threshold
suggest-compact.sh
脚本会在PreToolUse(编辑/写入)阶段运行,并:
  1. 跟踪工具调用 - 统计会话中的工具调用次数
  2. 阈值检测 - 在可配置的阈值(默认:50次调用)时给出建议
  3. 定期提醒 - 达到阈值后每25次调用提醒一次

Hook Setup

钩子设置

Add to your
~/.claude/settings.json
:
json
{
  "hooks": {
    "PreToolUse": [{
      "matcher": "tool == \"Edit\" || tool == \"Write\"",
      "hooks": [{
        "type": "command",
        "command": "~/.claude/skills/strategic-compact/suggest-compact.sh"
      }]
    }]
  }
}
添加到你的
~/.claude/settings.json
中:
json
{
  "hooks": {
    "PreToolUse": [{
      "matcher": "tool == \"Edit\" || tool == \"Write\"",
      "hooks": [{
        "type": "command",
        "command": "~/.claude/skills/strategic-compact/suggest-compact.sh"
      }]
    }]
  }
}

Configuration

配置

Environment variables:
  • COMPACT_THRESHOLD
    - Tool calls before first suggestion (default: 50)
环境变量:
  • COMPACT_THRESHOLD
    - 首次给出建议前的工具调用次数(默认:50次)

Best Practices

最佳实践

  1. Compact after planning - Once plan is finalized, compact to start fresh
  2. Compact after debugging - Clear error-resolution context before continuing
  3. Don't compact mid-implementation - Preserve context for related changes
  4. Read the suggestion - The hook tells you when, you decide if
  1. 规划完成后压缩 - 计划确定后,进行压缩以重新开始
  2. 调试完成后压缩 - 继续之前清理错误解决上下文
  3. 不要在实施过程中压缩 - 保留上下文以进行相关更改
  4. 查看建议 - 钩子会告诉你何时压缩,由你决定是否压缩

Related

相关内容

  • The Longform Guide - Token optimization section
  • Memory persistence hooks - For state that survives compaction
  • 长篇内容指南 - 令牌优化章节
  • 内存持久化钩子 - 用于在压缩后保留状态