Skip to main content
ChatCLI provides two powerful mechanisms for conversation history control: intelligent compaction to reduce context size without losing critical information, and rewind to restore the conversation to an earlier point.

/compact — Context Compaction

The /compact command reduces conversation history size so it fits within the model’s context window, preserving the most important information.

Usage Modes

Without arguments, runs the 3-level compaction pipeline:
/compact
The automatic pipeline follows this order:
  1. Level 1 — Trimming (near-lossless): strips <reasoning> tags, compacts XML, removes duplicates
  2. Level 2 — Structured summarization: extracts facts (files read, modified, commands executed, decisions) in bullet point format
  3. Level 3 — Emergency truncation: drops middle messages, keeping system prompt and recent messages

How It Works

Message Preservation

In both modes:
  • System messages are always fully preserved
  • Recent messages (4 in guided, 10 in automatic) are kept verbatim
  • Only the middle block is summarized or removed
  • Metadata indicates the message is a summary (IsSummary: true)

Example Output

After compaction, a summary message replaces the middle messages:
[GUIDED COMPACT — covering 42 earlier messages | instruction: "preserve auth architecture"]

## Files Read
- pkg/auth/handler.go (120 lines) - HTTP handlers for authentication
- pkg/auth/middleware.go (85 lines) - JWT validation middleware

## Files Modified
- pkg/auth/handler.go:45-60 - Added refresh token endpoint

## Key Decisions
- JWT tokens expire in 15 minutes with refresh token rotation
- Middleware validates at gateway level, not per-service

## Errors & Resolutions
- "token expired" panic in middleware → added nil check on claims

/rewind — Go Back in Time

/rewind lets you restore the conversation to an earlier point, undoing unwanted messages and responses.

How It Works

ChatCLI automatically saves checkpoints of the conversation before each LLM call. You can revert to any of those points.
/rewind
This displays an interactive menu:
  REWIND — Select a checkpoint to restore
  ─────────────────────────────────────────
  [1]  14:32:05  28 msgs  implement the refresh token endpoint
  [2]  14:28:12  24 msgs  fix the JWT middleware bug
  [3]  14:25:01  20 msgs  analyze the authentication module
  [4]  14:20:33  16 msgs  (start)

  Select [1-4] or (q)uit:
Select the checkpoint number to restore. The history is reverted to the exact state at that point, including all messages and context.

Keyboard Shortcut: Esc+Esc

Press Esc twice quickly (less than 500ms between presses) to open the rewind menu directly from the prompt, without typing /rewind.

Limits

  • A maximum of 20 checkpoints are kept (oldest ones are discarded)
  • Checkpoints exist only in the current session (not persisted to disk)
  • When rewinding, checkpoints after the restored point are removed

Unified History

ChatCLI uses a single history array shared across all modes (chat, agent, coder). This means:
  • Switching between /agent, /coder, and chat preserves all context
  • The AI doesn’t “forget” what was done in another mode
  • /compact and /rewind operate on the complete history, regardless of mode
Sessions saved with older ChatCLI versions that used separate per-mode histories are automatically converted when loaded — histories are merged in chronological order.

When to Use

/compact (automatic)

When ChatCLI warns that the context is large, or when you notice degraded responses.

/compact <instruction>

When you know exactly which information is critical and must not be lost during compaction.

/rewind

When the AI took a wrong path, generated incorrect code, or you want to try a different approach.

Esc+Esc

Quick shortcut for rewind without leaving your typing flow.

Next Steps