compact

compact is a skill for Claude Code, Codex from xiaobei930/cc-best. It costs 28 tokens per session (2,030 once invoked), scanned A, original, MIT.

A session-management guide that recommends shortening an agent's working context at sensible project milestones. Context is the information an agent can keep in its current conversation.

In plain words
What is it for?
Use it to decide when to summarize work after research, planning, completed milestones, or other clear phase changes.
Why use it?
It helps reduce the risk of losing important details or hitting context limits during long coding sessions.

Skill for Claude CodeCodex

Installs and runs on its own, but its text points at files inside its plugin — anything it tells you to read at a ${CLAUDE_PLUGIN_ROOT} path is only there once the plugin is installed. Installing the plugin gets both.

Part of the cc-best plugin — 19 skills, 44 commands, 8 agents, 20 hooks shipped together

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/xiaobei930/cc-best/compact
Any agent
npx skills add xiaobei930/cc-best --skill compact
Clone the repo
git clone --depth 1 https://github.com/xiaobei930/cc-best

Made for: Claude Code, Codex.

Or install cc-best, the plugin that ships this one along with the rest of its 19 skills, 44 commands, 8 agents, 20 hooks.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for compact

README.md
[![agentmods](https://agentmods.dev/badge/skills/xiaobei930/cc-best/compact.svg)](https://agentmods.dev/skills/xiaobei930/cc-best/compact)
Your own site
<a href="https://agentmods.dev/skills/xiaobei930/cc-best/compact"><img src="https://agentmods.dev/badge/skills/xiaobei930/cc-best/compact.svg" alt="Measured on agentmods" height="20"></a>
Per session 28 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,030 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00028 $0.02030
Opus 5 $0.00014 $0.01015
Sonnet 5 $0.00006 $0.00406
Haiku 4.5 $0.00003 $0.00203

Measured yesterday against content hash cfdf6ec81501, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

compact scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/compact/SKILL.md · 244 lines

How it starts

The opening of the file, as written. The whole thing — 244 lines — stays where its author put it; the contents beside it link to each section on GitHub.

策略性压缩技能

本技能用于在合适的时机建议上下文压缩,优化会话效率。

⚠️ 重要提示:Claude Code 官方的 auto-compact 有已知 bug(见下文),建议主动在 70% 时手动压缩。

官方 Auto-Compact Bug

Claude Code 官方的自动压缩功能存在已知问题:

Issue 版本 状态 问题描述
#18211 v2.1.7+ 已关闭 /cc-best:compact-context 和 auto-compact 同时损坏
#21853 v2.1.23+ 开放 /cc-best:compact-context 始终失败(回归 bug)
#16349 - - 警告和错误阈值相同,无预警

问题根因

  • 官方 auto-compact 设计在 95% 时触发,但压缩本身需要空间
  • 当上下文超过 ~85% 时,压缩可能因空间不足而失败
  • 警告阈值和错误阈值相同,用户无预警就触发硬限制

本插件的 Workaround

  • 默认启用 suggest-compact.js 钩子
  • 每 40 次工具调用提醒一次
  • 建议在 70% 时主动压缩

触发条件

  • 工具调用次数达到阈值(默认 40 次)
  • 从研究/探索阶段转向实现阶段
  • 完成一个里程碑后
  • 计划已最终确定
  • 上下文使用率 > 60%(建议主动压缩)

为什么需要策略性压缩

自动压缩的问题

  • 发生在任意点,经常在任务中途
  • 可能丢失重要上下文
  • 打断思维连贯性
  • 官方有 bug,可能失败

策略性压缩的优势

  • 在逻辑阶段边界压缩
  • 保留关键决策和上下文
  • 探索后、执行前压缩
  • 里程碑完成后压缩
  • 避免触发官方 bug

压缩时机

适合压缩的时机

1. 探索/研究完成,准备开始实现
2. 计划已确定,准备执行
3. 完成一个功能模块
4. 解决一个复杂问题后
5. 代码审查反馈处理完
6. 上下文使用率 > 70%

不适合压缩的时机

1. 调试进行中
2. 多文件修改未完成
3. 测试失败修复中
4. 重要决策讨论中
5. 复杂逻辑实现中途

阶段感知压缩 | Phase-Aware Compaction

管线阶段切换是最佳压缩时机。除了基于工具调用计数的提醒,系统还会在检测到阶段切换时主动建议压缩。

阶段切换压缩矩阵

阶段切换 压缩建议 原因
研究/探索 → 架构设计 ✅ 强烈 搜索上下文占用大量 token
架构设计 → 任务分解 ✅ 推荐 设计文本较长
任务分解 → 代码实现 ✅ 推荐 设计和实现上下文差异大
代码实现 → 测试验证 ⚠️ 视情况 测试可能需要代码细节
测试验证 → 下一任务 ✅ 推荐 清除 bug trace 噪音
失败方案 → 新方案 ✅ 强烈 清除死路思路

Read the full file on GitHub · 244 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 244 lines · 28 tokens per session scan A cfdf6ec81501

Subscribe to this mod's changes

compact is a skill published in the GitHub repository xiaobei930/cc-best (50 stars, last pushed 2mo ago), licensed MIT. It adds 28 tokens to every session and 2,030 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.

Related

Other skills, from other repositories

rtk-optimizer

Wrap high-verbosity shell commands with RTK to reduce token consumption. Use when running git log, git diff, cargo test, pytest, or other verbose CLI output that wastes context window tokens.

FlorianBruniaux/claude-code-ultimate-guide · 44 tokens

catchup

Restore context after /clear by summarizing recent work and project state.

FlorianBruniaux/claude-code-ultimate-guide · 16 tokens

session-save

Save the current session state (decisions, modified files, current status, and next steps) to a handoff file for later resume.

FlorianBruniaux/claude-code-ultimate-guide · 31 tokens

handoff-create

Generate a structured handoff document from the current session. Captures scope, relevant files with line numbers, key discoveries, work completed, current status, next steps, and code snippets. Use before ending a session or handing work to another agent.

FlorianBruniaux/claude-code-ultimate-guide · 53 tokens

handoff-update

Update an existing handoff document with current session progress. Applies section-specific merge rules: append-only for Work Done (never deletes history), replace for Status and Next Steps, merge for Files and Discoveries. Falls back to creating a new handoff if no source file is found.

FlorianBruniaux/claude-code-ultimate-guide · 60 tokens

handoff-resume

Load a handoff document and resume work from where a previous session left off. Parses scope, file references, completed work, and next steps, then confirms understanding before proceeding.

FlorianBruniaux/claude-code-ultimate-guide · 40 tokens