context-compression
できること
このスキルは、AIが非常に長い会話を管理する手助けをします。作業の終わった部分を要約し、重要な決定を残します。AIが話の流れを見失い始める長いセッションを行う人向けです。
使う場面
- ✓会話が20から30ターンほどを超えて長くなったとき。
- ✓AIが以前の提案を繰り返したり、決定を忘れたりし始めたとき。
- ✓作業の一つの段階が終わり、次の段階に進みたいとき。
スキルのリンク
https://github.com/vudovn/ag-kit/blob/main/.agents/skills/context-compression/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“このチャットは非常に長くなり、同じことを繰り返しています。終わったことを要約し、重要な決定を残してください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
このスキルは、長いツールの出力と終わった作業を、短い要約に置き換えます。重要な決定は残されるため、AIは文脈を失わずに作業を続けられます。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Context Compression — Long Session Management
Keep sessions productive by compressing completed work while preserving key decisions.
Overview
Long sessions (30+ turns) cause context degradation — the AI loses track of earlier work, repeats itself, or forgets decisions. Context compression proactively summarizes completed phases so the context window stays focused on active work.
Token Impact: Recovers 5,000-15,000 tokens in long sessions by replacing verbose tool outputs with semantic summaries.
When to Compress
| Signal | Action |
|---|---|
| Session has 20+ turns | Consider proactive compression |
| Agent repeats earlier suggestions | Context is saturated — compress now |
| User says "we already discussed this" | Compress immediately |
| Switching to a new phase of work | Compress the completed phase |
| Large tool output (500+ lines) | Micro-compact the output |
Compression Levels
Level 1: Micro-Compact (Tool Output)
Compress individual tool outputs while retaining semantic content:
❌ Before (raw grep output — 200 lines, ~4,000 tokens):
src/auth/jwt.ts:15: import { verify } from 'jsonwebtoken'
src/auth/jwt.ts:23: export function validateToken(token: string) {
src/auth/jwt.ts:24: try {
src/auth/jwt.ts:25: const decoded = verify(token, SECRET)
... (195 more lines)
✅ After (micro-compact — 5 lines, ~100 tokens):
Grep results for "jwt": Found 8 files, 42 matches.
Key files: src/auth/jwt.ts (main JWT logic), src/middleware/auth.ts (middleware),
src/api/login.ts (token creation). Token validation at jwt.ts:23-40.
Error handling at jwt.ts:42-55. Secret loaded from env at jwt.ts:8.
Level 2: Phase Summary
Replace a completed work phase with a summary:
❌ Before (full research transcript — ~3,000 tokens):
[turn 1] Read package.json...
[turn 2] Read src/index.ts...
[turn 3] Grep for "auth"...
[turn 4] Found 8 files related to auth...
[turn 5] Read src/auth/jwt.ts...
... (10 more turns of exploration)
✅ After (phase summary — ~200 tokens):
## Research Phase Complete
- Project: Next.js 15 app with JWT auth
- Auth files: 8 files in src/auth/, src/middleware/, src/api/
- Token flow: login → create JWT → store in httpOnly cookie → validate in middleware
- Bug location: src/auth/jwt.ts:45 — expiry check uses `<` instead of `<=`
- Decision: Fix the comparison operator, add edge case test
Level 3: Session Checkpoint
Full session summary for long-running work:
## Session Checkpoint (Turn 35)
### Completed
- [x] Researched auth system (8 files, JWT flow mapped)
- [x] Fixed token expiry bug in jwt.ts:45
- [x] Added edge case test in jwt.test.ts
- [x] Verified: all 42 tests passing
### In Progress
- [ ] Update API documentation
- [ ] Review related middleware
### Key Decisions
1. Keep httpOnly cookies (not localStorage) for token storage
2. Use `<=` for expiry check to include exact-moment expiry
3. Add 5-minute grace period for clock skew
### Files Modified
- src/auth/jwt.ts (line 45: comparison fix)
- tests/auth/jwt.test.ts (added 3 edge case tests)
Compression Protocol
Step 1: Identify Completed Phases
What work is DONE and won't be revisited?
→ Research findings already synthesized
→ Implementation already verified
→ Decisions already made and applied
Step 2: Extract Key Information
From the completed phase, preserve:
✅ Decisions made and WHY
✅ File paths and line numbers of changes
✅ Key findings that inform ongoing work
✅ Error messages or test results (summarized)
Discard:
❌ Step-by-step tool invocation details
❌ Full file contents that were read
❌ Exploratory dead-ends that didn't lead anywhere
❌ Verbose error stack traces (keep the message only)
Step 3: Write Summary
Use the Phase Summary format above.
Keep to 100-300 tokens per completed phase.
Include enough detail to resume work without re-reading.
Best Practices
- Compress phases, not facts — Individual decisions should stay, full transcripts should go
- Preserve "why" over "what" — Why a decision was made matters more than the exact commands run
- Never auto-compress — Always tell the user "I'm summarizing the completed research phase to keep context focused"
- Keep file references — Always preserve file paths and line numbers in summaries
- Checkpoint on phase transitions — Natural compression point when switching from research to implementation
よくある質問
いつ圧縮を頼むべきですか?
セッションが長いとき、AIが同じことを繰り返すとき、または作業の新しい段階に移るときに使います。
重要な決定が失われませんか?
このスキルは、残りを要約しながら重要な決定を残すように設計されています。
どれくらい役立ちますか?
長いセッションで余裕を生むためのものです。節約の度合いはセッションによって異なります。
詳細
作者による元の説明
Manage and compress conversation context in long sessions. Detect when context is growing large, summarize completed work phases, archive old findings while preserving key decisions. Prevents context degradation.
repo: vudovn/ag-kit
人気
- GitHubのスター
- 8.2k
- ランキング
- #12529
- ライセンス
- MIT
- 更新日
- 2026/10/18
コメント
- …
このリポジトリの他のスキル
batch-operations
8.2k関数の名前変更や古いimportの置き換えなど、同じ変更を多くのファイルに一度に行うよう、エージェントを支援します。
brainstorming
8.2k何か新しいものや複雑なものを作る前に、エージェントが確認の質問をして、まず目標を理解するよう教えます。
code-review-checklist
8.2k正しさ、セキュリティ、性能、テスト、ドキュメントに加え、AI特有のリスクも含めて、コードをレビューするためのチェックリストをエージェントに与えます。
code-review-graph
8.2k大きなプロジェクトでは、構造のマップを使ってコードをレビューし、変更の影響を受けるファイルだけを読むよう、エージェントを支援します。
似ているスキル
add-model-provider
394k安全なセットアップコマンドで新しいAIモデルプロバイダーをOpenClawに接続し、APIキーを平文で残さず、ライブテストを行うようエージェントを支援します。
acp-router
394kClaude CodeやCursorなどのコーディングアシスタントに、OpenClaw経由でタスクを渡し、その作業がそのツール内で行われるようエージェントを支援します。
browser-automation
394kログイン、タブ、応答しなくなったページからの復旧を含め、Webページを段階的に操作するようエージェントに教えます。