LLMs operate on tokens — units of text that the model processes. Costs are per-token; context windows are measured in tokens; performance scales with tokens.
For agents and skill systems, understanding token usage is operational essentials.
Tokens are units a tokenizer produces from text:
Rough rule: 1 token ≈ 4 characters of English. So 1000 tokens ≈ 750 words.
The exact tokenization depends on the model. Anthropic's tokenizer differs slightly from OpenAI's, etc.
The instructions the model receives at the start. Always present; counts every conversation.
Every message in the conversation. Grows as conversation progresses.
Each tool invocation has input and output. Both count.
Loaded skill content. Counts when invoked.
Read tool returns file content. The whole content goes into context.
Sent to the model. Generally cheaper.
Generated by the model. Generally more expensive (often 5× input).
For agents that read a lot and write a lot, both matter.
Direct cost. More tokens = more spend.
More tokens = slower responses. The model processes everything in context; longer context = longer per-turn time.
Models have maximum context windows. 200K-1M tokens for current Claude. Long conversations can exceed limits.
Beyond a certain point, more context doesn't help — the model focuses worse with too much information.
How many tokens did this conversation use? Cost = total × per-token rate.
Each turn (message + response) has a token count. Watching turn-by-turn shows where consumption spikes.
Tool calls have input (the call) and output (the result). Both add to context.
When invoked, how many tokens does this skill consume?
Anthropic's prompt caching: tokens reused from previous turns are cheaper. Cache hit ratio matters for cost.
Reading lots of files puts file content in context. Each read = file size in tokens.
For large files, partial reads (with offset/limit) save tokens.
The longer the conversation, the more history. Each turn carries the full prior context.
For very long sessions, summarization or context cleanup helps.
Tools that emit extensive output bloat context. See ToolOutputOptimization.
Each invoked skill adds its content. Multiple skills compound.
Subagents have their own contexts. Parent context isn't bloated by subagent work.
For independent work, subagents save parent context.
See SkillPerformance. Brief skills + references save tokens.
Read(file, offset=100, limit=20) instead of Read(file) for large files.
grep to find what you need; Read only the relevant portion.
Anthropic's caching reuses repeated context. Don't break cache by changing system prompt frequently.
Independent work in subagents keeps parent context cleaner.
Long conversations: summarize earlier portions.
Saving 50 tokens isn't worth a complex code change.
Optimize when usage shows a problem; not speculatively.
A skill that uses 200 more tokens but produces dramatically better output is worth it.
Shows token usage per conversation, per session.
Anthropic API returns token counts in responses:
{
"usage": {
"input_tokens": 1500,
"output_tokens": 300,
"cache_creation_input_tokens": 500,
"cache_read_input_tokens": 1000
}
}
For agent systems, log token usage per operation. Find which tools, skills, or workflows cost most.
Agent loads many large files when partial reads would do.
Tool dumps logs; all goes into context.
Skills that grow over time; don't trim.
Don't know which operations are expensive.
Context fills; quality degrades.
Frequent system prompt changes invalidate caches.
For agent systems: