ocr scan: on main loops amplify token usage to ~2.5M tokens for 95 files
OpenCodeReview Version
open-code-review v1.12.1 (1f5caf4d5)
Operating System
Windows
Installation Method
npm (global)
LLM Provider
OpenAI
Bug Description
I tried ocr scan on a small Java repository. Unlike ocr review, its architecture has very different token economics.
The scan selected 95 files and projected:
[ocr] full-scan: 148 file(s) discovered, reviewing 95
[ocr] estimated cost: ~95 file(s), est. 2.0M input + 511K output ≈ 2.5M total tokens
[ocr] scan dispatch: 12 batch(es) by by-language strategy
At first I assumed the estimate was wrong.
It is not.
The current implementation explains almost all of it before source size becomes significant.
internal/scan/estimate.go assumes:
promptOverheadTokens = 2000
avgMainRoundsPerFile = 7
avgOutputTokensPerRound = 700
With PLAN enabled, each file is estimated as:
PLAN input: file_tokens + 2,000
PLAN output: 400
MAIN input: 7 × (file_tokens + 2,000)
MAIN output: 7 × 700
For 95 files, fixed overhead alone is:
95 × 16,000 = 1,520,000 input tokens
95 × 5,300 = 503,500 output tokens
≈ 2.02M tokens
That is before most source-token amplification, dedup or project summary is counted.
So the ~2.5M projection is not caused by repository size. It is caused by the scan execution model.
Steps to Reproduce
- Open
https://github.com/aalsanie/codes - Configure an OpenAI provider/model.
- Run:
ocr scan
- Observe:
148 files discovered
95 files selected
~2.0M input + 511K output ≈ 2.5M total tokens
12 batches by by-language strategy
Expected Behavior
ocr scan should review a small repository without amplifying token usage to millions of tokens through per file PLAN and repeated MAIN loops.
Logs / Error Output
AI/LLM Disclosure
- [x] I didn't use AI/LLM to assist or generate the content above.
Additional Context
No response
Thanks for the detailed write-up — the token accounting you walked through is accurate, so let me clarify one thing and share where we stand.
The ~2.5M total tokens you quoted comes from the [ocr] estimated cost: line, which is a deliberately rough, worst-case heuristic printed before the run (fixed avgMainRoundsPerFile=7 × full file content, no cache credit). It's meant as an order-of-magnitude "are you sure?" warning, not a billing figure. The actual usage — including prompt-cache read/write — is reported afterward in the [ocr] Summary: line. In practice small files converge in fewer rounds and caching absorbs a good chunk of the repeated content, so real spend is usually well below the projection. Could you share the post-run Summary line from your scan? That's the number we should be reasoning about.
That said, your underlying point is fair: most of our effort so far has gone into review, and scan's per-file PLAN + repeated MAIN loop model does leave real room for improvement.
I'm going to close this issue for now, but not to dismiss it — I'll file a few focused, actionable issues (adaptive MAIN rounds, skipping PLAN for small/low-risk files, reflecting cache in the estimate) and link them back here, so it's easier for community contributors to pick up. Appreciate the thorough analysis.
There is no post run summary because I will not risk 2.5M tokens to scan a 93 files repository. Also; one correction: avgMainRoundsPerFile=7 is not worst-case; the default allows up to 60 tool rounds.
You are advertising:
~1/9 token cost
That may hold for the PR benchmark, but it clearly should not be presented as a general token efficiency claim when scan uses this execution model. Also, why close this before the focused follow up issues are created and linked? The underlying issue is acknowledged and still unresolved. This can be really misleading for users and can cost them real money!