> ## Documentation Index
> Fetch the complete documentation index at: https://docs.praison.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Context Optimizer CLI

> CLI reference for context optimization strategies and configuration

Configure context optimization behavior via CLI flags and interactive commands.

## CLI Flags

### Strategy

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# Smart optimizer (default, recommended)
praisonai chat --context-strategy smart

# Simple truncation
praisonai chat --context-strategy truncate

# Sliding window
praisonai chat --context-strategy sliding_window

# Summarize old messages
praisonai chat --context-strategy summarize

# Prune old tool outputs
praisonai chat --context-strategy prune_tools
```

| Strategy         | Description             | Best For             |
| ---------------- | ----------------------- | -------------------- |
| `smart`          | Intelligent combination | General use          |
| `truncate`       | Remove oldest messages  | Fast, simple         |
| `sliding_window` | Keep recent N messages  | Conversation flow    |
| `summarize`      | Compress old messages   | Context preservation |
| `prune_tools`    | Truncate tool outputs   | Tool-heavy workflows |

### Auto-Compaction

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# Enable (default)
praisonai chat --context-auto-compact

# Disable
praisonai chat --no-context-auto-compact
```

### Threshold

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# Trigger at 80% usage (default)
praisonai chat --context-threshold 0.8

# More aggressive (70%)
praisonai chat --context-threshold 0.7

# Less aggressive (90%)
praisonai chat --context-threshold 0.9
```

## Interactive Commands

### Manual Compaction

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
> /context compact
```

**Output:**

```
Optimizing context...
✓ Optimized: 45,000 → 30,000 tokens
Saved 15,000 tokens (33.3%)
Strategy: smart
```

### View Optimization History

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
> /context history
```

**Output:**

```
Optimization History
Time                     Event                Tokens       Saved
----------------------------------------------------------------------
2024-01-07T12:00:00      overflow_detected       45,000          -
2024-01-07T12:00:01      auto_compact           45,000     -15,000
```

### View Current Config

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
> /context config
```

Shows auto\_compact, threshold, and strategy settings.

## Environment Variables

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
export PRAISONAI_CONTEXT_AUTO_COMPACT=true
export PRAISONAI_CONTEXT_THRESHOLD=0.8
export PRAISONAI_CONTEXT_STRATEGY=smart
```

## config.yaml

```yaml theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
context:
  auto_compact: true
  compact_threshold: 0.8
  strategy: smart
  compression_min_gain_pct: 5.0
  compression_max_attempts: 3
```

## Strategy Details

### Smart (Recommended)

Combines multiple strategies intelligently:

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

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai chat --context-strategy smart
```

### Truncate

Simply removes oldest messages until under budget.

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai chat --context-strategy truncate
```

### Sliding Window

Keeps the most recent N messages that fit in budget.

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai chat --context-strategy sliding_window
```

### Summarize

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

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai chat --context-strategy summarize
```

### Prune Tools

Truncates old tool outputs while preserving recent ones.

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai chat --context-strategy prune_tools
```

## Troubleshooting

### Context still overflowing

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# Lower threshold
praisonai chat --context-threshold 0.6

# Use more aggressive strategy
praisonai chat --context-strategy truncate
```

### Losing important context

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# Use smart strategy
praisonai chat --context-strategy smart

# Or increase threshold
praisonai chat --context-threshold 0.9
```

### Auto-compact not triggering

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# Check if enabled
> /context config

# Verify threshold
> /context stats
```
