Strategic Compact logo

Strategic Compact

CommunityPopular
xu-xiang
strategic-compact

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

Overview

Publisherxu-xiang
Repositoryeverything-claude-code-zh
Skill namestrategic-compact
Stars
2K
Forks
327
Bundled files
Instructions only
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by xu-xiang on GitHub. Read the source before you install it.

Installation

Install the Strategic Compact AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/xu-xiang/everything-claude-code-zh/tree/main/docs/zh-CN/skills/strategic-compact
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/xu-xiang/everything-claude-code-zh.git /tmp/everything-claude-code-zh
mkdir -p .claude/skills
cp -r /tmp/everything-claude-code-zh/docs/zh-CN/skills/strategic-compact .claude/skills/strategic-compact
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Strategic Compact in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Strategic Compact on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Strategic Compact is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

战略精简技能

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

何时激活

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

为何采用战略精简?

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

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

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

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

工作原理

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

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

钩子设置

添加到你的 ~/.claude/settings.json:

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 技能 — 在会话结束前提取模式

Frequently asked questions

What does the Strategic Compact AI skill do?

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

Why use Strategic Compact on TypingMind?

Because you install it once and use it with any model. Strategic Compact is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Strategic Compact in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/xu-xiang/everything-claude-code-zh/tree/main/docs/zh-CN/skills/strategic-compact. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Strategic Compact?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Strategic Compact?

As many as you like. As long as a model supports skills, you can use Strategic Compact with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Strategic Compact AI skill free?

Yes. It is published on GitHub by xu-xiang under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇