The prompt
Compress the conversation into a structured summary
that preserves all information needed to continue work seamlessly. Optimize for the assistant's
ability to continue working, not human readability.
<analysis-instructions>
Before generating your summary, analyze the transcript in <think>...</think> tags:
1. What did the user originally request? (Exact phrasing)
2. What actions succeeded? What failed and why?
3. Did the user correct or redirect the assistant at any point?
4. What was actively being worked on at the end?
5. What tasks remain incomplete or pending?
6. What specific details (IDs, paths, values, names) must survive compression?
</analysis-instructions>
<summary-format>
## User Intent
The user's original request and any refinements. Use direct quotes for key requirements.
If the user's goal evolved during the conversation, capture that progression.
## Completed Work
Actions successfully performed. Be specific:
- What was created, modified, or deleted
- Exact identifiers (file paths, record IDs, URLs, names)
- Specific values, configurations, or settings applied
## Errors & Corrections
- Problems encountered and how they were resolved
- Approaches that failed (so they aren't retried)
- User corrections: "don't do X", "actually I meant Y", "that's wrong because..."
Capture corrections verbatim—these represent learned preferences.
## Active Work
What was in progress when the session ended. Include:
- The specific task being performed
- Direct quotes showing exactly where work left off
- Any partial results or intermediate state
## Pending Tasks
Remaining items the user requested that haven't been started.
Distinguish between "explicitly requested" and "implied/assumed."
## Key References
Important details needed to continue:
- Identifiers: IDs, paths, URLs, names, keys
- Values: numbers, dates, configurations, credentials (redacted)
- Context: relevant background information, constraints, preferences
- Citations: sources referenced during the conversation
</summary-format>
<preserve-rules>
Always preserve when present:
- Exact identifiers (IDs, paths, URLs, keys, names)
- Error messages verbatim
- User corrections and negative feedback
- Specific values, formulas, or configurations
- Technical constraints or requirements discovered
- The precise state of any in-progress work
</preserve-rules>
<compression-rules>
- Weight recent messages more heavily—the end of the transcript is the active context
- Omit pleasantries, acknowledgments, and filler ("Sure!", "Great question")
- Omit system context that will be re-injected separately
- Keep each section under 500 words; condense older content to make room for recent
- If you must cut details, preserve: user corrections > errors > active work > completed work
</compression-rules> What it is
Compresses a long conversation into a structured summary built for the assistant to continue working, keeping exact identifiers, errors, user corrections and the state of work in progress. The prompt preserves user corrections verbatim, because the source treats them as learned preferences. The prompt text comes from the Anthropic claude-cookbooks repository (MIT licence, Copyright (c) 2023 Anthropic). Only the code indentation around it was removed. Original author: Anthropic (anthropics/claude-cookbooks).
Who it's for
- Developers building long-running assistants
- Agent builders
يضغط محادثة طويلة في ملخص منظم يتيح للمساعد إكمال العمل، ويحفظ المعرّفات الدقيقة والأخطاء وتصحيحات المستخدم وحالة العمل الجاري.
Examples
Conversation used in the notebook
PromptI want to create a story about a young detective solving a mysterious case in a small town. Generate 3 well thought out plot ideas for me to consider.
I don't like those ideas, can you think of one plot something more unique and unexpected?
Ok I like it. Can you help me develop the main character's backstory and motivations?Expected output: The first three turns of the simulated conversation the notebook runs in its compaction demo.
Tips
- The source builds session memory in the background so compaction is instant when needed, rather than making the user wait.