
A large share of the output tokens in one OpenClaw session last week came from the agent rereading a file it had already summarized earlier in the same conversation. Why does an agent that already has a piece of information go fetch it again, and what would it take to stop that at the source? Most token budgeting runs on a quiet assumption: input tokens cover context, output tokens cover responses, multiply by the published rate, done. That model holds for a single prompt and response. It falls apart in a multi step agent loop full of repeated tool calls. A batch run across several sessions flagged a handful of cases where the same file read or search query got reissued within a short window, none wrong on its own, all of it money and latency with no new information attached. The rest of this post is about why that duplication keeps happening instead of getting caught by the agent itself, and what fixing it at the source would actually look like.
A GitHub discussion posted to the agentskills repository a few weeks back introduced a small Python CLI for parsing OpenClaw session logs, built to surface exactly this kind of waste: duplicate tool calls, low context efficiency, missed parallelization. I ran it against three weeks of real sessions, and my take is that the tool itself is unglamorous and rough around the edges in places, but the problem it points at is real, underreported, and mostly invisible until someone forces you to look at it in aggregate instead of turn by turn.
This post covers what that tool actually surfaces, where it falls short, and why an idea buried in its last section, standardized cost metadata in skill manifests, matters more than the CLI itself.
Measuring What Agent Sessions Actually Cost
Token Waste Found in OpenClaw Session Audit
Share of output tokens traced to redundant work
Duplicate file reads and search queries cost money and latency without adding new context.
Input tokens for context, output tokens for responses, multiply by the per million rate, done. That works fine for a single prompt and response. It falls apart almost immediately once you introduce a multi step agent loop with tool calls, because nobody's mental model budgets for repetition.
The audit casts a wider net than I expected going in. It measures:
- input and output token counts per session, split by turn
- duplicate tool call detection, flagging repeated calls with identical arguments
- a context efficiency score meant to capture how much of a session's tokens went toward actual output rather than context
- parallelization opportunities, where sequential tool calls had no dependency between them
- and cost estimates mapped across several common model pricing tiers, which changes how you read a report. A session that looks cheap under one model's pricing can look very different run against another provider's rates, and the tool does that translation automatically instead of making you do spreadsheet math afterward.
Running it is unremarkable on the surface:
pip install openclaw-agent-cost-optimizer
openclaw-cost analyze --session ./logs/session_2026-11-18.jsonl
openclaw-cost suggest --session ./logs/session_2026-11-18.jsonl --format terminal
openclaw-cost batch --dir ./logs/ --output report.html
The batch command earns its place in a weekly workflow. Running analyze on a single session tells you about one afternoon. Running batch across a week of logs tells you whether that afternoon was an outlier or the norm. In my case it was the norm.
The duplicate tool call detector produced the most uncomfortable number. Across several sessions, it flagged a number of instances where the same file read or the same search query got issued again within a short window, sometimes because the agent lost track of what it already knew, sometimes because a retry path reissued a call that had already succeeded. None of those calls were wrong individually. In aggregate they were just money and latency with no new information attached. So why does that duplication happen in the first place, instead of getting caught by the agent itself?
Catching Duplicate Tool Calls Before They Compound
How Duplicate Tool Calls Slip Through an Agent Session
It's tempting to assume a well built agent framework already deduplicates tool calls, caching repeated requests feels like such an obvious optimization that surely someone upstream handled it. The audit data says otherwise, at least in the sessions I looked at. The cause isn't really a bug. It's a tradeoff baked into how context windows get built turn by turn.
An agent reissues a tool call when it no longer has confident access to the result, even if that result is technically still somewhere in its context window. Push the original tool output far enough back in a long session and it falls outside the portion of context the model attends to effectively. Re calling the tool becomes the cheaper move from the model's perspective, even though it's the more expensive move from your wallet's perspective. The agent isn't being lazy. It's making a local decision that looks reasonable turn by turn and only looks wasteful once you aggregate.
Here's a simplified version of the detection logic the tool uses, reconstructed from its output behavior rather than copied from source (the actual implementation handles argument normalization with more care than this):
def find_duplicate_calls(tool_calls):
seen = {}
duplicates = []
for call in tool_calls:
key = (call["tool_name"], frozenset(call["arguments"].items()))
if key in seen:
duplicates.append({
"tool": call["tool_name"],
"first_seen_turn": seen[key],
"repeated_turn": call["turn_index"],
"tokens_wasted": call["output_tokens"],
})
else:
seen[key] = call["turn_index"]
return duplicates
That logic works cleanly on every call, in theory. Reality breaks it the moment arguments aren't perfectly identical. A file read with a trailing slash difference, a search query with reordered keywords that mean the same thing semantically but hash differently as a frozenset, both slip past detection entirely. I hit exactly this during testing: two calls doing the same search, one with quotes around a phrase and one without, counted as distinct. The tool reported zero duplicates on a session where I could see, reading the raw log myself, at least two calls doing identical work. Not a dealbreaker, but it means the waste numbers this tool reports are a floor, not a ceiling. Real duplication is probably higher than what gets flagged.
Caching, when the tool suggests it, isn't free either. The supports_caching flag only helps if the underlying skill or tool actually returns deterministic output for a given input, and plenty of tool calls, web search being the obvious case, don't. So the practical question becomes which categories of calls are safe to cache and which ones will serve stale data without telling you. That same question, how much to trust a number the tool hands you, comes up again with the next metric it reports.
Scoring Context Efficiency Without Overcorrecting
What the OpenClaw Cost Audit CLI Measures
| Metric Measured | What It Flags | Command |
|---|---|---|
| Token counts per turn | Input vs output split by turn | analyze |
| Duplicate tool calls | Repeated calls, identical arguments | analyze |
| Context efficiency score | Tokens toward output vs context | suggest |
| Parallelization gaps | Independent sequential calls | suggest |
| Cost across pricing tiers | Cost by model provider rates | batch |
Treat a context efficiency score like a golf score, lower effort required, higher number good, and you'll start optimizing toward it directly. That instinct runs exactly backwards in some cases, and the tool's own documentation flags this rather than let you walk into it blind.
Context efficiency, in this tool's formulation, tries to capture roughly what share of a session's total tokens ended up as output rather than input context. A session that spends a lot of input context pulling in file contents and documentation, then produces a comparatively short response, scores low on this metric. The naive read says that session was wasteful. The accurate read is that it might have needed a lot of grounding context to produce a short, correct answer, which is exactly the behavior you want from a careful agent handling a nontrivial codebase question.
Now compare that to a session with a high efficiency score, where output tokens make up a large share of total tokens. That pattern shows up when an agent generates long responses relative to the context it pulled in, which sounds efficient until you realize it can also describe an agent hallucinating confidently off thin context, because it never bothered to read the files it should have read first. I watched this happen directly: a session scored well above the median efficiency mark in a batch report, and when I actually read the transcript, the agent had skipped a documentation lookup it needed and just generated plausible sounding output instead. High score, wrong answer. The metric rewarded the exact failure mode I wanted it to catch.
None of this makes context efficiency scoring useless. It makes it a metric you read alongside the actual transcript, not instead of it, a limitation that applies to almost every automated agent metric I've used in the last year, not just this one. The tool does what it can with log data alone. It can't read your intent. Both failure modes covered so far, duplicate calls and misleading efficiency scores, get caught only after a session has already run. The last part of the GitHub thread proposes something that catches cost problems before the run instead.
Standardizing Cost Metadata Before Running Skills
The CLI itself isn't the interesting part of this discussion. The part of the original GitHub thread that stuck with me was the proposed cost_profile block for skill manifests, a small piece of structured metadata that skill authors could attach to a skill definition so platforms would know, before invocation, roughly what a skill was going to cost.
name: my-skill
cost_profile:
avg_input_tokens:
avg_output_tokens:
estimated_cost_per_run: ""
supports_caching: true
On paper this is a small addition. In practice it moves the decision point from after the run, when you're reading a cost report and wincing, to before the run, when a platform could throttle, warn, or substitute a cheaper skill variant. That's a meaningfully different intervention point, and it only works if enough skill authors actually fill in the metadata accurately rather than copy pasting a rough guess from one skill to the next.
That's the real risk with any proposed standard like this: adoption is uneven by default, enforcement of cost_profile accuracy doesn't really exist, and estimated_cost_per_run drifts the moment the underlying model pricing changes. A skill manifest written against one era's pricing will understate or overstate cost the next time a provider adjusts rates, and manifests aren't the kind of file people remember to revisit on a schedule.
Still, even an approximate, occasionally stale cost_profile field beats the current default, which is no signal at all until the invoice or the token counter tells you after the fact. A platform that reads supports_caching: true and skips a redundant call is strictly better off than one with no information, even when the flag is sometimes wrong. This is directionally useful, not solved, and it depends entirely on whether the agentskills ecosystem treats cost metadata as a first class field or an optional afterthought that only the careful authors bother to fill in.
That dependency is the actual answer to the question this post opened with. The agent in that OpenClaw session reread the file not because the CLI failed to catch it afterward, but because nothing in the skill or the platform told the agent, before the call, what rereading it would cost. Cost observability for agents sits roughly where testing observability sat eight or ten years ago: everyone agrees it matters, almost nobody has it wired into daily workflow by default, and the tools that exist get built by individual practitioners scratching their own itch rather than shipped as a platform primitive. openclaw-agent-cost-optimizer is exactly that kind of tool, a practitioner's audit script dressed up as a CLI, imperfect at argument normalization, honest about what its own metrics can and can't tell you. The fix isn't a better standalone CLI. It's cost data living as a field in the manifest, checked before the call happens, instead of a number you have to go digging for after the session is already over.