Sessions

Sessions are persistent conversations that maintain context, history, and file state across invocations.

Lifecycle

  1. Create — A new session starts when you run codecli or codecli run
  2. Use — Exchange messages, execute tools, modify files
  3. Suspend — Sessions auto-suspend when you exit (Ctrl+C or Ctrl+D)
  4. Resume — Continue with codecli --continue or codecli --session ID
  5. Fork — Create a branch from any point in the conversation
  6. Export — Save the session as JSON for sharing or archiving

Resuming Sessions

Terminal
bash
# Continue the most recent session
codecli -c
# Resume a specific session by ID
codecli -s abc123-def456
# List all sessions
codecli session list

Forking

Forking creates a new session from an existing point, letting you explore alternative approaches without losing the original conversation.

Export and Import

Terminal
bash
codecli export --session abc123 --output session.json
codecli import --input session.json

Compaction

As conversations grow, the context window fills up. Code CLI automatically compacts older messages using a multi-tier strategy:

TierTriggerAction
Light prune50% context usedRemove old tool outputs and summaries
Microcompact65% context usedCompress conversation history
Aggressive prune75% context usedStrip non-essential context
Emergency95% context usedFull context compression

Use /compact to manually trigger compaction at any time.

PreviousAuthenticationNextAgents & Multi-Agent