Sessions
Sessions are persistent conversations that maintain context, history, and file state across invocations.
Lifecycle
- Create — A new session starts when you run
codecliorcodecli run - Use — Exchange messages, execute tools, modify files
- Suspend — Sessions auto-suspend when you exit (Ctrl+C or Ctrl+D)
- Resume — Continue with
codecli --continueorcodecli --session ID - Fork — Create a branch from any point in the conversation
- Export — Save the session as JSON for sharing or archiving
Resuming Sessions
Forking
Forking creates a new session from an existing point, letting you explore alternative approaches without losing the original conversation.
Export and Import
Compaction
As conversations grow, the context window fills up. Code CLI automatically compacts older messages using a multi-tier strategy:
| Tier | Trigger | Action |
|---|---|---|
| Light prune | 50% context used | Remove old tool outputs and summaries |
| Microcompact | 65% context used | Compress conversation history |
| Aggressive prune | 75% context used | Strip non-essential context |
| Emergency | 95% context used | Full context compression |
Use /compact to manually trigger compaction at any time.