Skip to content
Development
Command

/compact-context

上下文压缩,减少 token 消耗

From plugin
4944 skills8 agents44 commands20 hooks
shell
$ npx -y skills add xiaobei930/cc-best --agent claude-code

Ships with cc-best. Installing the plugin gets this command.

How it fires

How this command gets triggered: by you, by Claude, or both.

  • Fires itselfClaude auto-loads it when your prompt matches the work.
  • You can call itInvoke it directly when you want it.
  • Slash command/compact-context

Context preview

What this command does when you run it.

上下文压缩,减少 token 消耗

Command definition

compact-context.md
description: 上下文压缩,减少 token 消耗
allowed-tools: Read, Write, Edit, Glob, Grep, TodoWrite

/compact-context - 上下文压缩

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

> ⚠️ **重要提示**:官方 auto-compact 有已知 bug,建议在上下文 **70%** 时主动执行压缩。 > 详见:[#18211](https://github.com/anthropics/claude-code/issues/18211)、[#21853](https://github.com/anthropics/claude-code/issues/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.md` 的 `last_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` 是临时文件,恢复后可删除
  • 如果正在进行关键操作,先完成再压缩

> **记住**: 压缩时机很重要——70% 是最佳压缩点,超过 85% 可能失败。宁可早压缩也不要等到来不及。

Read more
Read it on GitHub ↗
Ships withcc-best

Role-Driven Development Workflow for Claude Code Transform Claude into a complete development team. From product requirements to code review — one plugin, full workflow. Quick Start • Features • Workflow • Commands • FAQ

Get the whole plugin, auto-invoked
Stats
49
Stars
0
Views
3
Forks
Maintained
Maintenance
JavaScript
Language
MIT
License
1mo ago
Last commit
6mo ago
Created

Repo: xiaobei930/cc-best