Claude Code's New /compact Flag Cuts Token Usage 40%

Claude Code's New /compact Flag Cuts Token Usage 40%

Claude Code's new /compact flag reduces context usage by 40%, letting you work with larger codebases without hitting token limits.

3d ago·3 min read·12 views·via hn_claude_code, hn_claude_cli
Share:

What Changed — The /compact Flag

Claude Code recently introduced a /compact flag that significantly reduces token usage during agentic workflows. When activated, this flag optimizes how Claude Code processes and retains context from your codebase, particularly during extended coding sessions or when working with large repositories.

The flag works by implementing smarter context management—prioritizing relevant code sections, compressing less-critical historical context, and reducing redundant token consumption that typically occurs when Claude Code maintains conversation history alongside your code context.

What It Means For You — More Code, Less Cost

For developers working with substantial codebases, the /compact flag means you can:

  • Work with larger files without hitting context window limits
  • Maintain longer coding sessions without performance degradation
  • Reduce Claude Code usage costs by approximately 40% on token-heavy tasks
  • Keep more files open in your working context simultaneously

This is particularly valuable for full-stack developers who need to reference multiple components, APIs, and database schemas simultaneously, or when refactoring across large codebases.

Try It Now — How To Enable /compact

You can activate the compact mode in two ways:

1. CLI Command:

claude code --compact

2. In-session toggle:
During any Claude Code session, simply type:

/compact on

To verify it's working, check your token usage in real-time with:

/stats

You'll see "Compact Mode: Enabled" and noticeably lower token consumption for the same tasks.

When To Use It — And When Not To

Use /compact when:

  • Working with codebases over 10,000 lines
  • Doing large-scale refactoring
  • Running extended debugging sessions
  • Cost is a primary concern

Disable /compact when:

  • You need maximum reasoning depth on complex problems
  • Working on critical security or algorithm design
  • The 40% context reduction might omit important historical context

You can toggle it off anytime with:

/compact off

Pro Tip: Combine With /btw

The new /btw command for side conversations works particularly well with /compact enabled. Since /btw creates separate conversation threads, using it alongside /compact lets you explore alternative solutions or ask clarifying questions without bloating your main coding context.

Try this workflow:

/compact on
# Work on your main task
/btw "What's a more efficient algorithm for this?"
# Get answer in side thread, main context stays lean

This combination gives you the benefits of reduced token usage while maintaining the flexibility to explore different approaches.

AI Analysis

Claude Code users should immediately start using the `/compact` flag for any substantial coding work. The 40% token reduction is significant enough to change how you approach larger projects—you can now keep more files in context without worrying about hitting limits. Specifically, add `--compact` to your default Claude Code startup command or create an alias. For VS Code users, modify your Claude Code extension settings to enable compact mode by default. The performance trade-off is minimal for most coding tasks, and the cost savings add up quickly for daily users. When working on particularly complex logic or security-critical code, you might want to disable it temporarily, but for 80% of development work—feature implementation, bug fixes, refactoring—keep it on. Monitor your usage with `/stats` to see the exact impact on your workflow.
Original sourcetwitter.com

Trending Now

More in Products & Launches

View all