compact-context

A command that saves important project status and decisions, then creates a shorter summary of a long coding-agent conversation.

In plain words
What is it for?
Use it when a conversation is long, after a large feature, or before starting another task. It records progress and creates a summary that can be restored after clearing the conversation.
Why use it?
It reduces the amount of conversation the agent must keep in context while preserving unfinished work, assumptions, and key decisions for later recovery.

Command

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 commands/xiaobei930/cc-best/compact-context
Clone the repo
git clone --depth 1 https://github.com/xiaobei930/cc-best
Per session 9 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 981 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.00009 $0.00981
Opus 5 $0.00005 $0.00491
Sonnet 5 $0.00002 $0.00196
Haiku 4.5 $0.00001 $0.00098

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

Security

Grade A, and why

compact-context 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 2d ago.

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.

commands/compact-context.md · 121 lines

How it starts

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

/compact-context - 上下文压缩

智能压缩当前对话上下文,保留关键信息,释放 token 空间。

⚠️ 重要提示:官方 auto-compact 有已知 bug,建议在上下文 70% 时主动执行压缩。 详见:#18211#21853

使用场景

  • 对话过长,响应变慢
  • 完成一个大功能后,准备开始新功能
  • 上下文中有大量已完成任务的冗余讨论
  • 上下文使用率接近 70%(避免触发官方 bug)

执行流程

1. 状态保存(必须)

在压缩前,确保以下信息已持久化到文件:

□ 当前任务状态 → progress.md
□ 重要决策 → progress.md 决策记录表
□ 待确认假设 → progress.md 待确认列表
□ 未完成的代码变更 → 已保存到文件

2. 生成压缩摘要

创建 memory-bank/_compact_summary.md(临时文件):

# 上下文压缩摘要

## 会话概述

- 开始时间: [时间]
- 主要目标: [目标]
- 完成状态: [X/Y 任务完成]

## 关键决策

1. [决策1]: [原因]
2. [决策2]: [原因]

## 当前状态

- 正在进行: [任务]
- 阻塞项: [如有]

## 重要发现

- [发现1]
- [发现2]

## 下一步

- [待办1]
- [待办2]

3. 压缩策略

保留 移除
当前任务上下文 已完成任务的详细讨论
关键决策和原因 冗余的代码展示
待办事项 探索性的失败尝试
错误和解决方案 重复的文件读取
架构约束 已解决的问题讨论

4. 执行压缩

  1. 更新 progress.mdlast_checkpoint 字段
  2. 输出压缩摘要
  3. 提示用户执行 /clear

与官方命令的区别

命令 来源 行为 适用场景
/clear 官方 完全清除上下文 任务完成,开始新任务
官方 /compact 官方 自动压缩(有 bug 不推荐使用
本插件 compact-context 本插件 保存状态 + 生成摘要 压缩前的准备工作
本插件 catchup 本插件 恢复上下文 /clear 后恢复

命令格式说明:根据安装方式不同,命令格式也不同:

  • 通过 /plugin install 安装:使用 /cc-best:compact-context/cc-best:catchup
  • 直接 clone 到 .claude/:使用 /cc-best:compact-context/cc-best:catchup

输出格式

## 上下文压缩完成

### 已保存
- ✓ 进度状态 → progress.md
- ✓ 决策记录 → progress.md
- ✓ 压缩摘要 → _compact_summary.md

### 压缩摘要
[摘要内容]

### 下一步
执行官方 `/clear` 清除对话,然后执行 `/cc-best:catchup` 恢复上下文。

注意事项

  • 压缩前确保所有重要信息已保存
  • _compact_summary.md 是临时文件,恢复后可删除
  • 如果正在进行关键操作,先完成再压缩

Read the full file on GitHub · 121 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. 2d ago First seen · 121 lines · 9 tokens per session scan A f8eab806b2c6

Subscribe to this mod's changes

compact-context is a command published in the GitHub repository xiaobei930/cc-best (50 stars, last pushed 2mo ago), licensed MIT. It adds 9 tokens to every session and 981 once invoked, about $0.0000 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-08-30.