/context commands in the terminal to show, compact, or budget the active session.
How It Works
Quick Start
1
Interactive CLI
Launch chat or code mode, then inspect context:
2
Compact When Full
Reduce token usage without losing key history:
Interactive Commands
Use these commands inpraisonai chat or praisonai code interactive mode.
/context
Show context summary and statistics./context show
Alias for/context. Shows summary view.
/context stats
Show detailed token ledger by segment./context budget
Show budget allocation details./context dump
Write context snapshot to disk immediately./context on
Enable context monitoring./context off
Disable context monitoring./context path <path>
Set monitor output path./context format <human|json>
Set monitor output format./context frequency <turn|tool_call|manual|overflow>
Set monitor update frequency./context compact
Trigger manual context optimization./context history
Show optimization event history./context config
Show resolved configuration with precedence info.On unknown models the CLI falls back to a coarse per-model table (see Per-model context windows);
output_reserve is capped at window // 4 so small-window models still have a usable budget.Automatic Compaction (Interactive)
Inpraisonai chat and praisonai code, the worker loop watches the running conversation and compacts it for you when it nears the model’s usable budget.
1
Proactive check every turn
The loop skips compaction unless all of these are true:
auto_compactis enabled (defaultTrue).- The conversation has at least 4 messages — very short sessions are never compacted.
- Estimated tokens ≥
threshold × usable_budget(defaultthreshold = 0.8).
2
Reactive retry on provider errors
If the model still returns a context-length error, the loop forces one compaction and retries the turn once:The reactive retry honours
auto_compact — if you disable it with --no-context-auto-compact, the raw provider error surfaces so nothing is rewritten without your consent.Both paths reuse the same summariser as the manual
/context compact command. Manual /context compact is unchanged.Per-model context windows
The loop looks up the model’s context window in this order:litellm.get_model_info(model)— used when available.- Built-in fallback table (below).
- Default:
128,000tokens.
openai/… are stripped before lookup. The output_reserve (default 8000) is subtracted to give the usable budget, but is capped at window // 4 on small-window models so compaction doesn’t fire on every turn.
CLI Flags
Use these flags when startingpraisonai chat or praisonai code.
Auto-Compaction
Strategy
smart, truncate, sliding_window, summarize, prune_tools
Threshold
Monitoring
Redaction
Output Reserve
Estimation Mode
heuristic, accurate, validated
Mismatch Logging
Snapshot Timing
pre_optimization, post_optimization, both
Write Mode
sync, async
Show Config
Environment Variables
config.yaml
Precedence
Configuration is resolved in this order (highest to lowest):- CLI flags -
--context-*flags - Environment variables -
PRAISONAI_CONTEXT_* - config.yaml -
context:section - Defaults - Built-in defaults
Troubleshooting
Context overflow errors
The interactive loop already retries once after a provider context-length error (see Automatic Compaction (Interactive)). If overflows persist:Monitor not updating
Sensitive data in snapshots
Best Practices
Monitor Context Usage Regularly
Monitor Context Usage Regularly
Run
/context stats at the start of long sessions to understand your token budget before it fills up. Proactive monitoring prevents unexpected compaction mid-task.Set Threshold Below 90%
Set Threshold Below 90%
Use
--context-threshold 0.8 (80%) rather than the default. This leaves enough headroom for the compaction response itself without triggering at the very last moment. On very small models (e.g. gpt-4 at 8,192 tokens) leave the default threshold and output_reserve: the reserve is auto-capped at a quarter of the window so compaction still leaves you plenty of room to answer.Use Compact Strategy for Long Sessions
Use Compact Strategy for Long Sessions
The
compact strategy summarizes old turns intelligently. Use truncate only when you need to preserve exact recent messages and can afford to lose early conversation history.Enable Redaction for Sensitive Data
Enable Redaction for Sensitive Data
Always pass
--context-redact when your conversations may contain API keys, passwords, or PII. Redaction patterns are applied before any snapshot is written to disk.Related
Context Compression
Automatic context window management and compaction
Context Budgeter
Configure token budget allocation per segment

