Skip to content

Managing Token Usage and Costs in OpenClaw

I have been in that spot where a long session with an AI agent suddenly starts feeling sluggish, or the bill at the end of the month is higher than I expected. It is hard to stay on top of what is actually filling up your context window when you are focused on getting work done. I want to show you how OpenClaw tracks tokens and how you can keep your costs under control without losing the thread of your conversation.

  • An active OpenClaw installation.
  • An API key from your provider (required for cost estimation).
  • Access to the TUI, Web TUI, or CLI.

You can start monitoring your usage in about two minutes. Here is the fastest path to seeing what you are spending.

In any chat session, type /status. I like this because it gives you an emoji-rich card showing your session model, how much context you have used, and an estimated cost for the last response.

If you want to see the numbers after every single message, run this command:

/usage full

This appends a footer to every reply. If you only want the token count without the dollar amounts, use /usage tokens. This setting stays active for your entire session.

If you use Anthropic models, you can save money by using a heartbeat to keep the prompt cache “warm.” This prevents you from paying the higher “cache write” price repeatedly. Add this to your configuration:

agents:
defaults:
model:
primary: "anthropic/claude-opus-4-6"
models:
"anthropic/claude-opus-4-6":
params:
cacheRetention: "long"
heartbeat:
every: "55m"

To see exactly what is eating your tokens—whether it is the system prompt, tool results, or attachments—use these commands:

  • /context list
  • /context detail

Costs are showing as zero or missing OpenClaw only shows dollar costs if you are using an API key and have the pricing configured in models.providers.<provider>.models[].cost. If you are using OAuth, the system hides dollar costs and only shows token counts.

The system prompt is too large OpenClaw automatically builds a prompt including your workspace files like AGENTS.md or SOUL.md. If these files are huge, they might be hitting the default limit. You can adjust agents.defaults.bootstrapMaxChars (default is 20,000) to truncate these files and save space.

Cache costs are still high after an idle period Provider prompt caching only works within a specific time window. You can enable cache-ttl pruning in your Gateway configuration. This prunes the session once the cache expires, resetting the window so you don’t keep paying to re-cache an old, full history.

Managing tokens does not have to be a guessing game. By using the built-in status commands and setting up a heartbeat, you can keep your sessions efficient. If you need help setting up your specific provider pricing, check out the AI Setup Assistant.

OpenClaw

OpenClaw Expert

Still stuck?

If this page didn't answer your case, ask OpenClaw Expert for step-by-step guidance.