Skip to main content

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:
  1. Analyzes History: Reviews your full conversation context
  2. Generates Summary: Creates a comprehensive but concise summary
  3. Replaces Context: Swaps the detailed history with the summary
  4. Preserves Continuity: Maintains enough context to continue the conversation
  5. Reduces Tokens: Significantly decreases token count

How It Works

Before Compression

After Compression

Continuing After Compression

The AI maintains context from the summary.

When to Use

Approaching Token Limits

Long Conversations

After extended discussions:
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

Multiple Compressions

You can compress multiple times:
Each compression summarizes all context, including previous summaries.

Automatic Compression

Qwen Code can automatically compress when needed:
With auto-compress enabled:

Failed Compression

If compression fails:
Common causes:
  • 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
During compression:
  • The CLI shows a progress indicator
  • You cannot send new messages
  • Use Esc to cancel if needed

Best Practices

Don’t wait until you hit the token limit:
Monitor tokens regularly:
Compress when you’re over 70-80% of the limit.
Compress at natural breakpoints:
  • After completing a feature
  • Before starting a new phase
  • After resolving a complex issue
  • Before requesting major changes
For long-term projects, use both:
This maintains project knowledge across sessions.

Troubleshooting

Nothing to Compress

This means:
  • Conversation is too short (< 3 messages)
  • History was recently cleared
  • No meaningful content to summarize

Compression Too Aggressive

If important details are lost:
  1. Make key information explicit:
  2. 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