Concepts
Context management and cost saving
How clai prevents context bloat through tool output truncation, selective recall, and rate-limit recovery.
On this page
Long agentic sessions and verbose shell commands can quickly exhaust token budgets. clai keeps token usage predictable through built-in context controls.
Tool output truncation and recall
When a builtin tool (such as bash or rg) or an MCP tool produces output exceeding the configured inline threshold, clai truncates the message sent to the model and stores the full payload locally. The model can then inspect specific line or byte ranges on demand using the recall tool instead of re-sending megabytes of log output on every turn.
Scoped profiles and tool filtering
Rather than exposing every MCP server and builtin tool on every query, use -t="<glob>" or profile tools allowlists so the model only receives schemas for the tools relevant to the task.
Rate-limit backoff and partial conversation recovery
When a vendor returns a rate-limit error, clai parses the vendor’s retry window and backs off automatically. If you cancel a streaming query or tool loop with Ctrl+C, clai preserves the partial conversation state so you can resume with clai -c without paying to regenerate completed steps.