# How to reduce AI token usage with OpenClaw

Canonical: https://cwyn.com/pages/openclaw-guide-token-optimization.html
Last updated: 2026-12-01T09:12:56-05:00

OpenClaw model costs

To reduce AI token usage with OpenClaw, run `/context detail` on a repeatable task and find the largest input you can shorten. Prune stale tool results if they fill the prompt, or use `/compact` if earlier messages take up most of the space. Use `/usage tokens` before and after the change to compare input, output and cache counts on the same model.

Last updated December 1, 2026 · Published November 22, 2026

By CWYN · Checked against docs, not run · [OpenClaw token use](https://docs.openclaw.ai/reference/token-use) and [context reports](https://docs.openclaw.ai/context/) (as of Nov 22, 2026)

## 1. Measure one task

Pick a task you can repeat on the same model. Record these readings before you change its prompt or settings.

- `/usage tokens` adds a per-reply footer with the turn's token and cache details. Record the input, output and any cache reads or writes across the task.
- `/status` shows the session model, context usage, last response's input and output tokens, and cost when available.
- `/context detail` breaks down workspace instructions, tool schemas, skill metadata and transcript history. Use it to find the largest contributor.
- `/context map` shows those contributors as a treemap. Send a normal message first so there is a cached run report to display.

`/usage cost` gives a local summary from session logs. If the amount differs from your invoice, [reconcile OpenClaw usage with your provider bill](https://cwyn.com/pages/openclaw-guide-usage-bill-mismatch.html) for the same account, model and period. [Usage commands](https://docs.openclaw.ai/reference/token-use) and [context reports](https://docs.openclaw.ai/context/) (as of Nov 22, 2026).

[Estimate your own monthly bill with the free AI cost calculator](https://cwyn.com/score/ai-cost-calculator/?utm_source=cwyn&utm_medium=guide&utm_content=openclaw-guide-token-optimization).

## 2. Reduce what each turn carries

Workspace files. OpenClaw rebuilds its system prompt on each run. Check `/context list` for raw size, injected size and truncation marks before editing. Keep the instructions you need every turn in `AGENTS.md`. The default limits are 20,000 characters per file (`agents.defaults.bootstrapMaxChars`) and 60,000 characters in total (`agents.defaults.bootstrapTotalMaxChars`). Start with a file whose injected portion is large. [Check where AGENTS.md was cut off](https://cwyn.com/pages/openclaw-guide-agents-md-truncated.html). [Bootstrap limits](https://docs.openclaw.ai/reference/token-use) and [context inspection](https://docs.openclaw.ai/context/) (as of Nov 22, 2026).

Skills and tools. The prompt includes the skill list. Keep each description to one line under 160 characters and put the procedure in the skill instructions, which load on demand. Ask tools for the matching rows or log lines instead of a full dump. For screenshot-heavy sessions, lower `agents.defaults.imageMaxDimensionPx` and check that you can still read the detail needed for the task. [Writing skill descriptions](https://docs.openclaw.ai/tools/creating-skills) and [OpenClaw token use](https://docs.openclaw.ai/reference/token-use) (as of Nov 22, 2026).

Model choice. Try a cheaper model for verbose exploratory work or background tasks. Compare the cost per usable result, including retries. [Compare model prices](https://cwyn.com/pages/openclaw-guide-cheapest-model.html), then [set the default model](https://cwyn.com/pages/openclaw-guide-change-default-model.html). For other calls, check the [fallback order](https://cwyn.com/pages/openclaw-guide-model-fallbacks.html), [subagent model](https://cwyn.com/pages/openclaw-guide-subagent-model-cost.html) and [scheduled jobs](https://cwyn.com/pages/openclaw-guide-automation-costs.html). [OpenClaw cost guidance](https://docs.openclaw.ai/reference/token-use) (as of Nov 22, 2026).

## 3. Cache the part that repeats

OpenClaw's cost-first baseline pairs `cacheRetention: "short"` with `contextPruning.mode: "cache-ttl"`. On a direct Anthropic route, short retention uses the five-minute prompt cache. Put durable instructions, tool definitions and policy first so the beginning of the prompt stays the same as the conversation changes. Pick the model and thinking level at the start of the session. A model switch starts a new cache, and changing the thinking level can also break reuse. [Prompt caching and retention](https://docs.openclaw.ai/reference/prompt-caching/) (as of Nov 22, 2026).

If you use `cacheRetention: "long"` for Anthropic's one-hour cache, a useful automation running every `55m` in the same persistent session can keep that history warm. An isolated job cannot warm another conversation. Count every extra turn and cache write over the same period. Keep the cadence only if the total cost falls. [Persistent-session timing](https://docs.openclaw.ai/reference/token-use) and [cache lifetimes](https://docs.openclaw.ai/reference/prompt-caching/) (as of Nov 22, 2026).

When upgrading a Gateway with legacy heartbeat settings, run `openclaw doctor --fix` before starting the upgraded Gateway. Edit or disable the migrated job in Automations. [Migrate a heartbeat](https://cwyn.com/pages/openclaw-guide-heartbeat-migration.html) or [diagnose missing cache reads](https://cwyn.com/pages/openclaw-guide-prompt-cache-misses.html). [OpenClaw heartbeat migration](https://docs.openclaw.ai/gateway/config-agents/heartbeat-compaction-and-streaming) (as of Nov 22, 2026).

## 4. Prune tool output or compact history

Prune when old tool results dominate. OpenClaw disables context pruning by default. Enable it to trim stale tool results from the next model request while retaining the full transcript on disk. This example lets a client-side route consider pruning on the next request after an idle hour. The provider cache lifetime is a separate setting.

```
agents:
  defaults:
    contextPruning:
      mode: "cache-ttl"
      ttl: "1h"
```

The built-in pruning TTL is five minutes, and the bundled Anthropic plugin seeds one hour. On client-side routes, pruning waits for expiry and skips a pass below roughly 30% context use. Soft trimming keeps the beginning and end of a large result. Under heavier pressure, hard clearing can replace it with a placeholder. Image blocks stay intact. Direct Anthropic API-key calls using `anthropic-messages` at the standard endpoint use server-side clearing with token thresholds independent of this timer. [Context pruning settings](https://docs.openclaw.ai/gateway/config-agents/heartbeat-compaction-and-streaming) and [pruning by provider route](https://docs.openclaw.ai/concepts/session-pruning) (as of Nov 22, 2026).

Compact when the conversation itself dominates. Run `/compact` to write a persistent summary of older messages. By default, `agents.defaults.compaction.keepRecentTokens` keeps the most recent 20,000 tokens intact. Include the summarizing call when you compare costs. [Check the cost of the compaction model](https://cwyn.com/pages/openclaw-guide-compaction-model-cost.html). [OpenClaw compaction](https://docs.openclaw.ai/reference/session-management-compaction/compaction) (as of Nov 22, 2026).

## What do cache reads save on the same workload?

Use the calculator's opening workload and the monthly worksheet's model, Claude Sonnet 4.6, on a direct Anthropic API key. These token counts are assumptions. The per-turn figures are averages across a session. 10 turns × (500 system + 400 history + 100 user) = 10,000 input tokens per session. 10 × 100 output = 1,000 output tokens per session. At 4 sessions a day × 30 days, both cases cover 120 sessions.

The uncached case bills all input at the regular rate. For the cached case, the calculator assumes follow-ups arrive within five minutes and each turn adds the same amount of new context. Once the prefix reaches the model's cache minimum, new cacheable input is billed as a five-minute write and eligible repeated input as a read. Each input token appears in exactly one billing category. Rates are USD per million tokens. [Anthropic pricing for Claude Sonnet 4.6](https://platform.claude.com/docs/en/about-claude/pricing) (as of 2026-11-19).

### Without caching

- Regular input. 1,200,000 tokens × $3 ÷ 1M ≈ $3.60
- Output. 120,000 tokens × $15 ÷ 1M ≈ $1.80

30-day token cost $5.40.

### With cache reads and writes

- Regular input. 327,273 tokens × $3 ÷ 1M ≈ $0.98
- Cache reads. 654,545 tokens × $0.3 ÷ 1M ≈ $0.20
- Cache writes (5m). 218,182 tokens × $3.75 ÷ 1M ≈ $0.82
- Output. 120,000 tokens × $15 ÷ 1M ≈ $1.80

30-day token cost $3.80.

The difference is $1.60 over 30 days. Displayed counts round to whole tokens and totals use unrounded charges. Include the cost of any extra automation turns when you compare your own bills.

For your own comparison, repeat the task after changing one setting. The [weekly worksheet in the OpenClaw Token Bill Kit](https://cwyn.com/pages/pack-openclaw-token-bill-kit.html) gives you a place to record what each run cost and where the figures came from.

To include hosting and other charges alongside model usage, use the [OpenClaw monthly cost worksheet](https://cwyn.com/pages/openclaw-guide-cost-per-month.html).

## What changes the number?

- Caching. Check how much input was read, written or billed at the regular rate after an idle gap.
- Tool-result size. Count how many subsequent turns carry a large search result or log.
- Bootstrap size. Compare the injected sizes before and after shortening workspace files.
- Compaction. Count the summary call alongside the smaller requests that follow it.
- Cron or automation cadence. Add every scheduled model turn over the period you compare.
- Model choice. Match each call, including background work, to the rates of the model that handled it.

[OpenClaw token accounting](https://docs.openclaw.ai/reference/token-use) and [compaction behavior](https://docs.openclaw.ai/reference/session-management-compaction/compaction) (as of Nov 22, 2026).

## OpenClaw token usage FAQ

### Which memory files add to the prompt?

OpenClaw can inject the root `MEMORY.md` when present. Lowercase `memory.md` is legacy repair input and is never injected. Daily files in `memory/*.md` load on demand through memory tools. [Workspace memory and token use](https://docs.openclaw.ai/reference/token-use) (as of Nov 22, 2026).

### How much of one tool result can reach the model?

The live cap is 16,000 characters for context windows below 100,000 tokens, 32,000 at 100,000 or more, and 64,000 at 200,000 or more. A single result is also capped at 30% of the context window. Returning only the lines you need keeps the next prompt smaller even below those caps. [Tool-result limits](https://docs.openclaw.ai/reference/token-use) (as of Nov 22, 2026).

### Why does /usage full show tokens without a cost?

OpenClaw estimates cost from the model's configured USD rates per million tokens for input, output, cache reads and cache writes. If both pricing and a recorded amount are missing, the footer omits the cost. Use the provider's usage record to fill the gap. [Usage cost estimates](https://docs.openclaw.ai/reference/token-use) (as of Nov 22, 2026).

## Related guides

- [OpenClaw alternatives for chat, coding and routines](https://cwyn.com/pages/openclaw-guide-alternatives.html)
- [OpenClaw runaway API bill: find and stop the token spend](https://cwyn.com/pages/openclaw-guide-runaway-api-bills.html)
- [OpenClaw auth profile cooldown: check which credential can run](https://cwyn.com/pages/openclaw-guide-auth-profile-cooldown.html)
- [OpenClaw Fast mode billing: check which requests cost more](https://cwyn.com/pages/openclaw-guide-fast-mode-billing.html)

## Next steps

- [All 135 OpenClaw guides](https://cwyn.com/guides/openclaw/)
- [OpenClaw setup walkthrough](https://cwyn.com/setup/openclaw/)
- [Free AI cost calculator](https://cwyn.com/score/ai-cost-calculator/?tool=openclaw)
- [OpenClaw Token Bill Kit ($24.95)](https://cwyn.com/pages/pack-openclaw-token-bill-kit.html)

### Price your own token usage

[Use the free AI cost calculator](https://cwyn.com/score/ai-cost-calculator/)

Choose OpenClaw, API key and your model. Enter your session counts, input and output, then compare your cache reads and writes with an uncached run.

## Email me the OpenClaw safety checklist

Get the OpenClaw Production Safety Checklist with its readiness scorecard and operator prompts.

Email address

Email me this file. Also send up to 4 short follow-up emails with tips and one related CWYN product. Unsubscribe any time. [Privacy policy](https://cwyn.com/pages/privacy.html)

### Track the next bill

The [OpenClaw Token Bill Kit ($24.95)](https://cwyn.com/pages/pack-openclaw-token-bill-kit.html) is an optional paid kit with a weekly bill review worksheet and routing and cache settings.

OpenClaw Token Bill Kit $24.95

Audit OpenClaw model spend with verified token controls, routing and cache snippets, and a weekly bill review worksheet.
