Overview
The/compress command uses AI to generate a concise summary of your conversation history and replaces the full context with this summary. This reduces token usage while preserving important information, allowing you to continue longer conversations.
Usage
In Interactive Mode
Alternative Names
The following aliases are available:/compress/summarize
In Non-Interactive Mode
What It Does
When you run/compress, the command:
- Analyzes History: Reviews your full conversation context
- Generates Summary: Creates a comprehensive but concise summary
- Replaces Context: Swaps the detailed history with the summary
- Preserves Continuity: Maintains enough context to continue the conversation
- Reduces Tokens: Significantly decreases token count
How It Works
Before Compression
After Compression
Continuing After Compression
When to Use
Approaching Token Limits
Long Conversations
After extended discussions:Continuing Related Work
Preserve context while starting a new phase:Before Major Changes
Compress before requesting large code changes:Output Example
Interactive Mode
JSON Output
Compression Quality
The compression algorithm preserves: ✅ Key Decisions: Important choices made during the conversation✅ Code Structure: Architecture and implementation details
✅ Current State: What has been completed
✅ Next Steps: Planned or discussed next actions
✅ Context: Why certain approaches were chosen What may be lost: ⚠️ Exact Wording: Specific phrasing of questions
⚠️ Failed Attempts: Solutions that didn’t work
⚠️ Full Code: Only key snippets are preserved
⚠️ Minor Details: Small clarifications or tangents
Compress vs Clear
Decision Matrix
| Scenario | Use Compress | Use Clear |
|---|---|---|
| Continue same project | ✅ | ❌ |
| Switch to new project | ❌ | ✅ |
| Near token limit | ✅ | ✅ |
| Need fresh context | ❌ | ✅ |
| Preserve decisions | ✅ | ❌ |
| Remove sensitive data | ❌ | ✅ |
Multiple Compressions
You can compress multiple times:Automatic Compression
Qwen Code can automatically compress when needed:Failed Compression
If compression fails:- Network issues
- API rate limits
- Very short conversations (nothing to compress)
Integration Examples
CI/CD Pipeline
Scheduled Compression
Performance Impact
Compression typically takes:- Small conversations (< 5,000 tokens): 2-5 seconds
- Medium conversations (5,000-10,000 tokens): 5-10 seconds
- Large conversations (> 10,000 tokens): 10-20 seconds
- The CLI shows a progress indicator
- You cannot send new messages
- Use Esc to cancel if needed
Best Practices
Compress Proactively
Compress Proactively
Don’t wait until you hit the token limit:
Check Token Usage
Check Token Usage
Monitor tokens regularly:Compress when you’re over 70-80% of the limit.
Strategic Compression Points
Strategic Compression Points
Compress at natural breakpoints:
- After completing a feature
- Before starting a new phase
- After resolving a complex issue
- Before requesting major changes
Combine with Project Summary
Combine with Project Summary
For long-term projects, use both:This maintains project knowledge across sessions.
Troubleshooting
Nothing to Compress
- Conversation is too short (< 3 messages)
- History was recently cleared
- No meaningful content to summarize
Compression Too Aggressive
If important details are lost:-
Make key information explicit:
-
Use project summary for permanent details:
Repeated Compressions Degrading
After many compressions, quality may degrade. Consider:See Also
/clear Command
Clear conversation for a fresh start
/stats Command
Monitor token usage and statistics
Context Management
Understanding context and tokens
Session Management
Managing sessions and history
