Repository navigation
Description
Description
Add a new /compact command that compresses the current message history into a smaller, more efficient representation while preserving essential information and context continuity.
Use Case
When working on long conversations or complex projects, message history can consume significant context space, leading to:
- Context limit pressure: Approaching model token limits
- Performance degradation: Slower responses due to large context
- Loss of recent context: Important information gets truncated
- Inefficient token usage: Redundant or verbose information taking up space
The /compact command addresses these issues by:
- Preserving key information: Maintaining critical decisions, code changes, and context
- Reducing redundancy: Eliminating repetitive exchanges and verbose explanations
- Maintaining continuity: Keeping enough context for coherent conversation flow
- Optimizing token usage: Maximizing available space for new interactions
This is especially valuable for users working on large codebases, long debugging sessions, or extended feature development.
Proposed Solution
Implement a /compact command that processes message history and creates a condensed version:
1. Message Analysis
Analyze conversation history to identify:
- Key decisions and outcomes: Important conclusions reached
- Code changes: Files modified, functions added/changed
- Active context: Current working files, ongoing tasks
- User preferences: Established patterns and requirements
- Error resolutions: Successfully resolved issues
2. Compression Strategy
Apply intelligent compression techniques:
- Summarize repetitive exchanges: Convert back-and-forth debugging into concise summaries
- Consolidate file operations: Group multiple edits to the same file
- Extract key insights: Preserve important discoveries and decisions
- Maintain recent context: Keep last few messages at full detail
- Preserve tool results: Retain essential command outputs and file contents
3. Output Format
🗜️ Context Compacted: 2,845 tokens → 1,230 tokens (57% reduction)
Preserved:
• 3 key decisions and outcomes
• 8 file modifications across 5 files
• Current task: implementing user authentication
• Last 2 full message exchanges
• 4 important tool results
Previous conversation summary available with /compact --show
4. Compression Modes
- Default: Balanced compression maintaining good context
- Aggressive (
--aggressive): Maximum compression for tight limits - Conservative (
--conservative): Minimal compression, safer approach - Preview (
--preview): Show what would be compressed without applying
Technical Implementation
Command Structure
- Location:
src/core/commands/compact.ts - Integration: Add to existing command registry
- Usage:
/compact [--aggressive|--conservative|--preview|--show]
Message Processing Pipeline
- Message Classification: Categorize messages by importance and type
- Content Analysis: Identify key information using pattern matching
- Redundancy Detection: Find repetitive or verbose content
- Summarization Logic: Create concise summaries of lengthy exchanges
- Context Preservation: Ensure critical context remains intact
Compression Techniques
- Template-based summaries: Use structured formats for common patterns
- Code diff compression: Represent file changes more efficiently
- Tool result filtering: Keep only essential command outputs
- Conversation threading: Group related message chains
- Smart truncation: Remove verbose explanations while keeping conclusions
Safety Measures
- Backup original: Store original context in case of reversion needed
- Validation checks: Ensure compressed context maintains coherence
- User confirmation: Optional preview before applying compression
- Undo capability: Allow restoration of original context
Integration Points
- Message history access: Interface with ChatSession message storage
- Token counting: Use existing tokenization for before/after metrics
- Context management: Update session context efficiently
- Tool integration: Handle tool call summaries appropriately
Acceptance Criteria
-
/compactcommand appears in help menu - Compresses message history while preserving key information
- Shows before/after token count and reduction percentage
- Provides different compression modes (default, aggressive, conservative)
- Includes preview mode to show changes before applying
- Maintains conversation continuity and context flow
- Preserves recent messages at full detail
- Handles tool results and code changes appropriately
- Includes safety measures (backup, validation, confirmation)
- Shows summary of what was preserved/compressed
- Optional display of compressed content with
--show
Additional Context
This feature would be particularly valuable for:
- Long development sessions: Extended coding conversations
- Complex debugging: Multi-step problem-solving processes
- Code review workflows: Lengthy back-and-forth discussions
- Feature development: Extended implementation conversations
- Local model users: Working with smaller context windows
The compression should be intelligent enough to maintain the essential context needed for the AI to continue providing relevant assistance while significantly reducing token consumption.
Technical Considerations
- Compression quality: Balance between size reduction and information preservation
- Context coherence: Ensure compressed context doesn't break conversation flow
- Performance: Compression process should be fast and efficient
- Reversibility: Consider ability to expand or restore original context
- Model compatibility: Work across different AI providers and models
Type of Change
- New feature
- Bug fix
- Breaking change
- Documentation update
Activity
feat: add /compact command for context compression
feat: add /compact command for context compression
Avtrkrb commentedon Nov 23, 2025
@JimStenstrom @will-lamerton
An additional feature to be considered, having auto compression of the context length without the user explicitly having to call the
/compactcommand would be nice.We can probably have the following:
conservative& allow users to modify that as per their wish.This will be useful in the scenario that the context length is consumed when a sequence of file edits or tool calls are happening & before the agent has produced a final response to the user.
will-lamerton commentedon Nov 23, 2025
Hey @Avtrkrb - I like this, I'll amend the spec!
will-lamerton commentedon Nov 23, 2025
Hey @Avtrkrb - here is an updated spec, let me know what you think?
Compact Command Specification
Description
Add a new
/compactcommand that compresses the current message history into a smaller, more efficient representation while preserving essential information and context continuity.Use Case
When working on long conversations or complex projects, message history can consume significant context space, leading to:
The
/compactcommand addresses these issues by:This is especially valuable for users working on large codebases, long debugging sessions, or extended feature development.
Proposed Solution
Implement a
/compactcommand that processes message history and creates a condensed version:1. Message Analysis
Analyze conversation history to identify:
2. Compression Strategy
Apply intelligent compression techniques:
3. Output Format
4. Compression Modes
--aggressive): Maximum compression for tight limits--conservative): Minimal compression, safer approach--preview): Show what would be compressed without applyingAuto-Compacting Feature
Overview
In addition to the manual
/compactcommand, implement an automatic compacting feature that triggers when context usage reaches a configurable threshold.Configuration
Add an
autoCompactconfiguration option toagents.config.json:{ "nanocoder": { "providers": [...], "autoCompact": { "enabled": true, "threshold": 80, "mode": "default", "notifyUser": true } } }Configuration Options
enabledtruethreshold60mode"conservative""default","aggressive", or"conservative"notifyUsertrueThreshold Behavior
When context usage reaches the configured threshold percentage:
(current_tokens / max_tokens) * 100 >= threshold, initiate compactionnotifyUseris enabled, display:Context Monitoring
Implement continuous context monitoring:
The monitor should:
User Override
Users can override auto-compact settings per session:
/compact --auto-off: Disable auto-compacting for current session/compact --auto-on: Enable auto-compacting for current session/compact --threshold 90: Temporarily set threshold to 90%Technical Implementation
Command Structure
source/commands/compact.tssource/commands/index.ts/compact [--aggressive|--conservative|--preview|--show|--auto-on|--auto-off|--threshold <n>]Configuration Types
Add to
source/types/config.ts:Context Monitor Implementation
Create
source/utils/context-monitor.ts:Message Processing Pipeline
Compression Techniques
Safety Measures
Integration Points
prompt-history.tsmessage storageuseAppStateconfig/index.tsHook Integration
Add auto-compact logic to
source/hooks/useChatHandler.tsx:Acceptance Criteria
Manual Compact Command
/compactcommand appears in help menu--showAuto-Compact Feature
autoCompactconfiguration option available inagents.config.json--auto-on,--auto-off,--threshold)/statuscommand shows current context usage and auto-compact settingsExample Configuration
No Configuration (uses defaults)
Auto-compacting works out of the box with no configuration required:
true60%conservativetrueDisable Auto-Compact
{ "nanocoder": { "providers": [...], "autoCompact": { "enabled": false } } }Custom Threshold
{ "nanocoder": { "providers": [...], "autoCompact": { "threshold": 75 } } }Full Configuration (override all defaults)
{ "nanocoder": { "providers": [...], "autoCompact": { "enabled": true, "threshold": 70, "mode": "default", "notifyUser": false } } }Aggressive Auto-Compact for Small Context Models
{ "nanocoder": { "providers": [...], "autoCompact": { "enabled": true, "threshold": 60, "mode": "aggressive", "notifyUser": false } } }Additional Context
This feature would be particularly valuable for:
The compression should be intelligent enough to maintain the essential context needed for the AI to continue providing relevant assistance while significantly reducing token consumption.
Technical Considerations
Type of Change
Avtrkrb commentedon Nov 23, 2025
The updated spec looks awesome @will-lamerton ! Just a suggestion, I think the starting range for default context usage percentage can be set to 50-60%. I have some previous bad experiences when using Roo Code with Qwen 30B A3B from a homelab server that when context usage hit 50% the model started hallucinating. The default threshold value can still be 80%...
will-lamerton commentedon Nov 23, 2025
@Avtrkrb Yeah now you mention it I've had similar experiences, even with Nanocoder. I'll amend and set as the main spec for now. Open to anyone else's thoughts!
Pahari47 commentedon Jan 7, 2026
Hii @will-lamerton, let me work on this
will-lamerton commentedon Jan 7, 2026
Go for it 😎
Expand review with 8 additional bugs from manual testing