Skip to main content
Configure context optimization behaviour via CLI flags and interactive commands. The user chats in the CLI; context flags compact history before the model hits token limits.

How It Works

Quick Start

1

Simple Usage

Inside the session, compact manually when needed:
2

With Configuration

Or set defaults in config.yaml:

CLI Flags

Strategy

Auto-Compaction

Threshold

Interactive Commands

Manual Compaction

Output:

View Optimization History

Output:

View Current Config

Shows auto_compact, threshold, and strategy settings.

Environment Variables

config.yaml

Strategy Details

Combines multiple strategies intelligently:
  1. First tries non-destructive pruning
  2. Falls back to sliding window
  3. Uses truncation as last resort

Truncate

Simply removes oldest messages until under budget.

Sliding Window

Keeps the most recent N messages that fit in budget.

Summarize

Compresses old messages into a summary (requires LLM call).

Prune Tools

Truncates old tool outputs while preserving recent ones.

Troubleshooting

Context still overflowing

Losing important context

Auto-compact not triggering

Best Practices

smart combines pruning, sliding window, and summarisation — use it unless you have a specific reason not to.
Trigger compaction at 0.7–0.8 so optimisation runs before the model hard-fails on context overflow.
Check token usage before manually compacting — /context history shows what each compaction saved.

Context Optimizer

Python API and strategy reference

Context Monitor

Watch optimisation in action

Context Budgeter

Set token budgets per session

Intelligent Conversation Compaction

Long-session compaction deep-dive