Context Compaction
Carry Code’s intelligent context compression feature automatically manages conversation length, keeping you efficient during long conversations.
Why Do We Need Compression?
Section titled “Why Do We Need Compression?”AI conversations have an important limitation: Token count. Each AI model has a maximum token limit (e.g., 128K, 200K, etc.).
When conversations get long:
- Exceeding the limit prevents continued conversation
- Sending long contexts increases API costs
- Affects AI response speed
Carry Code’s intelligent compression solves these problems.
How It Works
Section titled “How It Works”Automatic Compression
Section titled “Automatic Compression”Carry Code automatically detects conversation length and when approaching the token limit:
- Analyze conversation - Identify key and secondary information
- Compress secondary content - Simplify early detailed conversations
- Preserve key information - Keep important code and decisions
- Maintain coherence - So AI still understands the context
Compression Strategy
Section titled “Compression Strategy”| Content Type | Handling |
|---|---|
| Key code | Fully preserved |
| Important decisions | Fully preserved |
| Error messages | Condensed |
| Casual chat | Heavily simplified |
| Historical details | Selectively compressed |
Manual Trigger Compression
Section titled “Manual Trigger Compression”Command
Section titled “Command”/compactManually trigger context compression.
Use Cases
Section titled “Use Cases”- When conversation gets too long
- Want to clear unnecessary history
- Want to save API costs
Compression Effect
Section titled “Compression Effect”After compression:
- Token count significantly reduced
- Key information still preserved
- Conversation can continue
Configuring Compression Behavior
Section titled “Configuring Compression Behavior”Configuration File
Section titled “Configuration File”Configure in ~/.carry/carrycode.json:
{ "compaction": { "enabled": true, "threshold": 80000, "preserveKeyInfo": true }}Parameter Description
Section titled “Parameter Description”| Parameter | Description | Default |
|---|---|---|
enabled | Enable automatic compression | true |
threshold | Token threshold to trigger compression | 80000 |
preserveKeyInfo | Preserve key information | true |
Impact on Conversations
Section titled “Impact on Conversations”What Happens
Section titled “What Happens”- Information simplification - Early detailed conversations are condensed
- Key points preserved - Important code and decisions are kept
- Continue chatting - You can continue the previous task
What Doesn’t Happen
Section titled “What Doesn’t Happen”- ❌ Won’t lose key information for current task
- ❌ Won’t delete important code
- ❌ Won’t affect current conversation context
Usage Tips
Section titled “Usage Tips”1. Regular Compression
Section titled “1. Regular Compression”When conversation exceeds a certain length, proactively use /compact:
- Keep conversations efficient
- Save costs
- Avoid hitting token limits
2. Create New Sessions When Appropriate
Section titled “2. Create New Sessions When Appropriate”For completely different tasks, creating a new session is better:
- Avoid context confusion
- Keep each task clear
3. Use Plan Mode
Section titled “3. Use Plan Mode”When you don’t need to write code, use Plan mode:
- Won’t generate new code content
- Context is simpler
Combined with Session Management
Section titled “Combined with Session Management”| Operation | Effect |
|---|---|
/session new | Brand new blank context |
/compact | Compress current context |
/session switch | Switch to other context |
Q: Will compression lose important information?
Section titled “Q: Will compression lose important information?”No. The compression algorithm prioritizes preserving:
- Key code snippets
- Important decisions
- Current task-related information
Q: Can I continue previous work after compression?
Section titled “Q: Can I continue previous work after compression?”Yes. AI will understand the compressed context, and you can continue previous tasks.
Q: How to disable automatic compression?
Section titled “Q: How to disable automatic compression?”Set "enabled": false in the config file, but it’s recommended to keep it enabled to avoid hitting token limits.
Next Steps
Section titled “Next Steps”- Dual Mode - Use with modes
- Session Management - Manage multiple sessions
- Approval Modes - Control AI permissions