productivity

>Use /compact to Save Context

commandscontext-windowperformance

Ever hit that frustrating moment where Claude suddenly can't remember what you were working on five minutes ago? You're deep into a complex debugging session or building a multi-file project, and suddenly Claude acts like you're strangers meeting for the first time. This happens because Claude's context window—the amount of conversation history it can remember—has limits.

The /compact command is your secret weapon for keeping long conversations focused and efficient. Instead of losing hours of valuable discussion or starting over from scratch, you can compress your conversation into a concise summary that preserves the essential information while freeing up space for new interactions.

Understanding Context Window Limitations

Before diving into /compact, you need to understand what you're working with. Claude's context window is like a notepad with limited pages—once it's full, older information gets pushed out to make room for new content.

You'll typically hit context limits when:

  • Working on large codebases with multiple file reviews
  • Debugging complex issues that require extensive back-and-forth
  • Building projects that span multiple conversations
  • Providing detailed specifications or requirements

The warning signs are obvious: Claude starts forgetting earlier parts of your conversation, asks you to re-explain things you've already covered, or gives responses that seem disconnected from your project's context.

How to Use the /compact Command

Using /compact is straightforward—just type the command when your conversation starts feeling unwieldy. Here's the basic syntax:

/compact

Claude will then create a comprehensive summary of your conversation, preserving:

  • Key decisions and requirements
  • Code snippets and solutions discovered
  • Project goals and constraints
  • Important context about your specific use case

The summary becomes your new conversation baseline, and you can continue working without the baggage of a bloated conversation history.

Strategic Timing for Compacting

Knowing when to compact is as important as knowing how. Here are the optimal moments:

After Major Milestones

Compact after completing significant phases of your project:

// After successfully implementing authentication
const authMiddleware = (req, res, next) => {
  const token = req.headers.authorization?.split(' ')[1];
  if (!token) return res.status(401).json({ error: 'No token' });
  // ... rest of implementation
  next();
};

// This would be a good time to /compact before moving to the next feature

At this point, you'd use /compact to summarize the authentication implementation details and decisions, then continue with the next feature.

Before Context Switch

When you need to pivot to a different aspect of your project:

# You've been working on data processing
def process_user_data(raw_data):
    cleaned = clean_data(raw_data)
    validated = validate_schema(cleaned)
    return transform_for_storage(validated)

# Now you need to switch to frontend work
# Perfect time to /compact and preserve the backend logic

When Explanations Get Repetitive

If you find yourself re-explaining the same concepts or Claude asking for clarification on previously discussed topics, it's time to compact.

Advanced Compacting Strategies

Pre-Compact Preparation

Before running /compact, set the stage for a better summary:

Before we compact, let me highlight the key decisions we've made:
1. Using PostgreSQL for user data storage
2. Implementing JWT authentication with 24-hour expiry
3. Rate limiting set to 100 requests per minute
4. Error handling follows RFC 7807 Problem Details format

/compact

This ensures important decisions are prominently featured in the summary.

Project-Specific Context Preservation

For complex projects, explicitly state what context must be preserved:

Key context to preserve in compacting:
- Database schema: users, posts, comments tables
- API endpoints: /auth/login, /users/:id, /posts
- Current bug: race condition in comment creation
- Next milestone: implement real-time notifications

/compact

Multi-Session Continuity

Use /compact to bridge conversations across different sessions:

Session summary for tomorrow:
- Project: E-commerce API rebuild
- Current status: Payment processing 80% complete
- Blockers: Stripe webhook validation failing
- Files modified: payment.controller.js, webhook.service.js

/compact

Common Pitfalls to Avoid

Over-Compacting

Don't compact too frequently. Each compaction loses some nuance, so use it strategically rather than reflexively. A good rule of thumb: compact when your conversation exceeds 50-75 exchanges or when you notice context degradation.

Under-Preparing

Compacting without highlighting key information often results in important details being lost in the summary. Always do a quick mental review of critical context before compacting.

Ignoring Code Context

When working with code, make sure your latest working versions are clearly identified before compacting:

// WORKING VERSION - include in compact summary
function calculateTax(amount, region) {
  const rates = {
    'US': 0.08,
    'CA': 0.13,
    'EU': 0.20
  };
  return amount * (rates[region] || 0.05);
}

// This version had bugs - don't prioritize in summary

Timing Mistakes

Avoid compacting in the middle of debugging complex issues or during active problem-solving. Wait until you've reached a natural stopping point or resolution.

Maximizing Post-Compact Productivity

After compacting, help Claude get back up to speed quickly:

Based on our compacted conversation, I'm continuing work on the user authentication system. 
Current focus: implementing password reset functionality.

This immediate context setting ensures smooth continuation without losing momentum.

Reference your compacted summary when needed:

As established in our earlier discussion (now compacted), we're using bcrypt 
for password hashing with a cost factor of 12. I'm now implementing the 
reset token generation.

What's Next

Once you've mastered /compact, explore other context management strategies. Learn about breaking complex projects into focused conversation threads, using Claude's /reset command for clean slates, and organizing your development workflow around Claude's strengths and limitations.

Consider combining /compact with other productivity commands like /help for quick reference and /clear for truly fresh starts. The goal is building a sustainable workflow that lets you tackle increasingly complex projects without hitting cognitive or technical walls.

Remember: effective context management isn't just about the tools—it's about developing intuition for when and how to use them. Start experimenting with /compact in your next multi-session project and watch your productivity soar.