Skip to main content
Complete reference for all context management CLI commands and flags. The user runs /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 in praisonai chat or praisonai code interactive mode.

/context

Show context summary and statistics.
Output:

/context show

Alias for /context. Shows summary view.

/context stats

Show detailed token ledger by segment.
Output:

/context budget

Show budget allocation details.
Output:

/context dump

Write context snapshot to disk immediately.
Output:

/context on

Enable context monitoring.
Output:

/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.
Output:

/context history

Show optimization event history.
Output:

/context config

Show resolved configuration with precedence info.
Output:
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)

In praisonai 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_compact is enabled (default True).
  • The conversation has at least 4 messages — very short sessions are never compacted.
  • Estimated tokens ≥ threshold × usable_budget (default threshold = 0.8).
When it fires you’ll see:
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:
  1. litellm.get_model_info(model) — used when available.
  2. Built-in fallback table (below).
  3. Default: 128,000 tokens.
Provider prefixes like 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 starting praisonai chat or praisonai code.

Auto-Compaction

Strategy

Options: smart, truncate, sliding_window, summarize, prune_tools

Threshold

Value: 0.0 to 1.0 (default: 0.8)

Monitoring

Redaction

Output Reserve

Estimation Mode

Options: heuristic, accurate, validated

Mismatch Logging

Snapshot Timing

Options: pre_optimization, post_optimization, both

Write Mode

Options: sync, async

Show Config

Shows resolved configuration and exits.

Environment Variables

config.yaml

Precedence

Configuration is resolved in this order (highest to lowest):
  1. CLI flags - --context-* flags
  2. Environment variables - PRAISONAI_CONTEXT_*
  3. config.yaml - context: section
  4. 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:
If you’d rather see the raw provider error than let the loop rewrite history, disable auto-compaction:

Monitor not updating

Sensitive data in snapshots

Best Practices

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.
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.
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.
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.

Context Compression

Automatic context window management and compaction

Context Budgeter

Configure token budget allocation per segment