The page leanprompt report --html writes for SamurAIGPT/llm-wiki-agent at commit 86ab47d, audited 2026-11-27. Every figure on this page is an estimate from reading the code, not a measurement of the app in use. Corrections and takedown: email info@podwarden.com or open an issue. Back to the audit of SamurAIGPT/llm-wiki-agent
leanprompt audit of SamurAIGPT/llm-wiki-agent
Unattended audit: nobody was asked during the run, so priority, volume and prices were left open; the questions for the owner are listed at the end.
7 places where this app pays for tokens it doesn't need
The biggest, at docs/automated-sync.md:41, about 2M tokens per 1,000 calls: the documented nightly job runs tools/ingest.py on every .md file under raw/ every night, whether or not the file changed since it was last ingested.
Togetherabout 3M tokens per 1,000 calls An estimate from the code, not a measurement. Findings that overlap are counted once. If the open questions hold, add about 1.4M per 1,000 calls.
Tokens per 1,000 calls, by finding, and each one's share of the total
Plus 1 open question to confirm, listed after the findings.
Plus 7 other problems the audit found, listed after the findings. Not scored.
What this costs you
Every figure here is an estimate from the code, not a measurement. Findings the audit marked as overlapping are counted once in the totals, the largest of each group; other findings can still overlap. Money is not part of the score. The table lists this app's findings first, largest first, then its open questions, then the questions for the server's administrator, then the findings the project already knows about, which are not in the totals.
Finding
Where
Tokens per 1,000 calls
LP-GE-06
docs/automated-sync.md:41
1.5M prompt, 500k output
LP-GE-14
tools/refresh.py:147
750k prompt, 250k output
LP-PC-01
tools/_utils.py:69
400k not cached; the fix writes 200k to the cache at the write price
LP-GE-05
tools/ingest.py:241
225k prompt, 123k output
LP-GE-14
tools/heal.py:35
120k prompt, 20k output
LP-GE-05
tools/build_graph.py:272
81k prompt, 26k output
LP-GE-10
tools/ingest.py:222
30k output
LP-PC-02 (open question)
tools/build_graph.py:238
1.4M not cached
To see this in money, add to leanprompt.yaml:
volume: {calls_per_month: N}: how many calls the app makes a month (with targets:, on each entry)
prices: per model: input, cached_input and output per 1M tokens (US dollars, or set currency), with source and checked date (or, self-hosted, engine: {prefill_tokens_per_second: N})
leanprompt never guesses a volume or a price. Your coding agent can look up the provider's current price page and add it with the date; how.
What's wrong and what to change
8 open, 0 fixed. Largest first, by the audit's estimate of tokens lost per 1,000 calls.
1
The documented nightly job runs tools/ingest.py on every .md file under raw/ every night, whether or not the file changed since it was last ingested.
Finding 1. docs/automated-sync.md:41mediumLP-GE-06how often is assumed
Each run is a full ingest call.
What to change
Ingest only new or changed files: keep a hash per raw file (ingest.py already computes one at line 199) and skip files whose hash is unchanged, or have the job call tools/refresh.py once its hash bug is fixed.
Why it matters
An ingest call sends the schema, the wiki context and the whole source (about 15k tokens) and asks for up to 8,192 tokens back. Re-ingesting an unchanged file pays for all of it again and also adds a duplicate index line.
How often it happens
The code shows the problem; how often it happens is assumed. To measure it: whether the nightly job from docs/automated-sync.md is in use, and how many of the files it ingests were unchanged since the previous night (compare raw/ hashes with the previous run's log)
Overlaps
Finding 2 loses some of the same tokens; the totals count the larger once.
Estimate
about 1.5M prompt and 0.5M output tokens per 1,000 calls (estimate)What the estimate assumes
ingest is 30% of calls at about 15k prompt and 5k output tokens; one third of all ingests are nightly re-runs of unchanged files. Call mix assumed: 300 ingest, 500 graph, 100 query, 50 heal, 50 lint per 1,000.
2
refresh.py compares a 16-character hash (line 72) with the hash it stores after a refresh, which is the full 64-character hash (line 147).
Finding 2. tools/refresh.py:147mediumLP-GE-14how often is assumed
They never match, so every plain run re-ingests every source page that has a source_file, as if all were stale.
What to change
Store the same form that is compared: sha256(raw_content, truncate=16) at line 147 (or compare full hashes at line 72).
Why it matters
Each source re-ingested for nothing is a full ingest call (about 15k prompt tokens and up to 8k output), and it adds a duplicate entry to index.md each time.
How often it happens
The code shows the problem; how often it happens is assumed. To measure it: how often refresh.py is run without --force (from shell history or a scheduler)
Overlaps
Finding 1 loses some of the same tokens; the totals count the larger once.
Estimate
about 0.75M prompt and 0.25M output tokens per 1,000 calls (estimate)What the estimate assumes
one in six ingest calls comes from refresh.py runs over unchanged sources; same call mix and ingest sizes as above. The mismatch came in with the shared sha256() helper (PR #52); before it refresh.py hashed both sides to 16 characters.
3
Every call goes through one helper that sends a single user message with no cache mark.
Finding 3. tools/_utils.py:69highLP-PC-01how often is assumed
The tools default to Anthropic models, and Anthropic only reuses a prompt that carries a mark, so batch ingests resend the 2,000-token schema in full each time.
What to change
Let call_llm take a stable prefix and send it as its own content block with cache_control: {type: ephemeral} (litellm passes it through for Anthropic); pass the schema there in ingest.py and the shared part in build_graph.py.
Why it matters
In a batch, each ingest starts with the same schema, and with the reordering above every graph call starts with the same page list. Without a mark Anthropic bills all of it as new input every time.
How often it happens
The code shows the problem; how often it happens is assumed. To measure it: how often ingests run in batches (a directory or the nightly job) on an Anthropic model
Estimate
about 0.4M prompt tokens per 1,000 calls not served from cache, net of about 0.2M written (estimate)What the estimate assumes
two thirds of ingests run in batches, the next call arriving within the 5-minute lifetime (an ingest that writes 5k tokens takes about a minute); schema 7,856 characters, about 2,000 tokens. The graph-loop part is counted in the reordering finding, not here.
4
Ingest asks for one JSON object holding the full source page, the full rewritten overview and every entity and concept page, capped at 8,192 output tokens.
Finding 4. tools/ingest.py:241highLP-GE-05how often is assumed
When the answer stops at the cap the JSON is cut off, parsing fails, the whole answer is discarded and the program exits; the next run (or the nightly job) sends the same request with the same cap.
What to change
Check the finish reason: if it is length, do not resend unchanged; raise the cap or split the request (source page first, then entity pages), and say so to the user.
Why it matters
A cut-off ingest pays for the full prompt and 8,192 output tokens and keeps nothing, and the overview it must rewrite grows with every source, so the same file fails again.
How often it happens
The code shows the problem; how often it happens is assumed. To measure it: how often ingest prints 'Error parsing API response' with a /tmp/ingest_debug.txt that ends mid-JSON
Estimate
about 0.12M output and 0.23M prompt tokens per 1,000 calls (estimate)What the estimate assumes
5% of ingest calls reach the 8,192 cap; each failed attempt is re-run once unchanged.
5
heal.py saves a page for a missing entity such as [[Andrej Karpathy]] as entities/Andrej_Karpathy.md, because sanitize_filename turns spaces into underscores.
Finding 5. tools/heal.py:35mediumLP-GE-14how often is assumed
The missing-entity check compares the link text with file names as they are, so the entity is still missing next time and is generated again on every run.
What to change
Keep spaces in the file name (drop the underscore join at line 35; the path checks already prevent traversal), or compare names after the same normalisation in lint.find_missing_entities.
Why it matters
The documented nightly job runs heal.py every night, so each multi-word entity costs one call per night forever, and the link stays broken.
How often it happens
The code shows the problem; how often it happens is assumed. To measure it: how many missing entities have multi-word names (count [[links]] with a space that lint lists as missing)
Estimate
about 0.12M prompt and 20k output tokens per 1,000 calls (estimate)What the estimate assumes
heal is 5% of calls at about 3,000 prompt and 500 output tokens; 80% of its calls are repeats for multi-word names. The underscore join came in with PR #56.
6
Edge inference is capped at 1,024 output tokens.
Finding 6. tools/build_graph.py:272mediumLP-GE-05how often is assumed
A page with many relationships gets a cut-off JSON, which fails to parse; the page is not checkpointed, so every later build sends the same request with the same cap and fails the same way.
What to change
Check the finish reason; on length, retry once with a higher cap or ask for at most N edges, and checkpoint the result.
Why it matters
Each failing page costs a full call on every build and never gets its edges.
How often it happens
The code shows the problem; how often it happens is assumed. To measure it: how often build_graph prints '[WARN] Invalid JSON' for the same page on two consecutive runs
Estimate
about 26k output and 81k prompt tokens per 1,000 calls (estimate)What the estimate assumes
5% of inference calls hit the cap; graph calls are 50% of the mix at about 3,250 prompt tokens.
7
Ingest asks for JSON in the prompt text only and parses it with regular expressions.
Finding 7. tools/ingest.py:222mediumLP-GE-10how often is assumed
An answer with a stray quote or prose around it is discarded and the program exits.
What to change
Request JSON mode or a JSON schema through litellm's response_format on models that support it, and keep the local repair as a fallback.
Why it matters
A discarded ingest answer is up to 8k output tokens paid for nothing.
How often it happens
The code shows the problem; how often it happens is assumed. To measure it: how often ingest fails to parse an answer that was not cut off
Estimate
about 30k output tokens per 1,000 calls (estimate)What the estimate assumes
2% of ingest answers that are not cut off still fail to parse.
Open questions
Findings outside this repository, or whose behaviour the code cannot show. They still count in the score. Each says what to confirm.
8
In the relationship-inference loop, each prompt starts with the page being analysed and only then lists all wiki pages, the extracted edges and the rules, which are the same for every page in the run.
Finding 8. tools/build_graph.py:238highLP-PC-02
The shared part comes after the part that changes, so no provider can reuse it.
To confirm
which provider and model the graph build runs on: OpenAI or Gemini automatic caching, or Anthropic with a cache mark and a model whose minimum cacheable size is at or below the shared part (about 2,750 tokens for 200 pages)
Change, if confirmed
Put the instructions, the page list and the edge summary first and the page id and content last, so every call in a run shares one long prefix.
Why it matters
For a 200-page wiki the shared part is about 2,750 of 3,250 prompt tokens per call, recomputed at full price on each of the hundreds of calls in one build.
Estimate
about 1.4M prompt tokens per 1,000 calls not served from cache (estimate)What the estimate assumes
graph inference is 50% of calls; 200 pages, about 10 tokens per page entry, 30 edges at 15 tokens, 300 tokens of rules. Cached reads need OpenAI or Gemini automatic caching, or on Anthropic a cache mark (finding below) and a model whose minimum is at or below the prefix (1,024 on Sonnet 4.6, 4,096 on Haiku 4.5, so a 200-page wiki is too small on Haiku 4.5).
Other problems the audit found
Problems the audit checked in the code that cost no tokens of their own, such as a spend meter that ignores cache tokens or a cut-off answer accepted as complete. They are not scored. Check each one before you change anything.
N1
A healed multi-word entity is still missing, so its links stay broken
Note 1. tools/lint.py:76not scored
heal.py saves [[Andrej Karpathy]] as entities/Andrej_Karpathy.md (sanitize_filename joins words with underscores, heal.py:35, since PR #56). find_missing_entities compares the link text with file stems unchanged, so 'andrej karpathy' never matches 'andrej_karpathy': lint keeps listing the entity as missing, keeps telling the user to run heal.py, and the [[links]] stay broken in Obsidian.
What to change
Keep spaces in the file name (drop the underscore join at heal.py:35; the separator and null-byte removal and the resolved-path check already keep the file inside wiki/entities/).
The default models are retired, so every tool fails unless LLM_MODEL is set
Note 2. tools/_utils.py:50LP-GE-13highnot scored
call_llm defaults to claude-3-5-sonnet-latest and heal, query and build_graph default to claude-3-5-haiku-latest (heal.py:89, query.py:100, build_graph.py:272). Anthropic retired Sonnet 3.5 on 2025-10-28 and Haiku 3.5 on 2026-02-19; requests to retired models return 404. README.md:296 says the scripts need only ANTHROPIC_API_KEY.
What to change
Default to current models, for example claude-sonnet-4-6 and claude-haiku-4-5, and document LLM_MODEL and LLM_MODEL_FAST in the README.
N3
An ingest failure ends a whole refresh run and its progress is not saved
Note 3. tools/refresh.py:91not scored
ingest() calls sys.exit(1) on a parse failure (ingest.py:248). refresh_page catches only Exception, and SystemExit is not one, so the loop stops and save_refresh_cache (line 152) never runs; sources already refreshed in that run are refreshed again next time.
What to change
Have ingest raise an exception instead of exiting (and exit only in __main__), or catch SystemExit in refresh_page; save the cache after each page.
N4
One bad answer stops a batch ingest
Note 4. tools/ingest.py:248not scored
In batch mode (directory or several files, lines 398-399) a single parse failure calls sys.exit(1), so the remaining files are never ingested and the nightly log shows only the first failure.
What to change
Raise from ingest() and let the batch loop log the failure and continue.
N5
Edge inference is told the edges listed come from this page, but gets the first 30 of the whole wiki
Note 5. tools/build_graph.py:229not scored
existing_edge_summary is the first 30 extracted edges of all pages, built once, and the prompt labels it 'Already-extracted edges from this page'. The model cannot avoid repeating this page's own wikilinks, and about 450 tokens of unrelated edges ride on every call.
What to change
Build the summary per page from the edges whose 'from' is the current page.
N6
heal.py ignores LLM_MODEL_FAST
Note 6. tools/heal.py:89not scored
heal intends the fast model (default haiku) but reads LLM_MODEL, so anyone who sets LLM_MODEL to a large model runs heal on it, unlike query.py:100 and build_graph.py:272, which read LLM_MODEL_FAST.
query answers (4,096 cap) and the lint report (lint.py:298, 3,000 cap) are used without checking the finish reason; with --save a cut-off answer is written to wiki/syntheses and indexed as if whole.
What to change
Check response.choices[0].finish_reason in call_llm and warn or raise when it is length.
Fix it with your coding agent
Paste this into Claude Code, Codex, Cursor or any coding assistant. It will check each finding against your code and propose fixes one at a time, asking before it changes anything.
Please check and fix the LLM-call findings from a leanprompt audit of this repository.
1. If the leanprompt skills are not installed for you here, install them: npx leanprompt@0.1.0-dev.15 install
2. Read .leanprompt/findings.json and leanprompt-report.md. If they are missing, use the list below.
3. Check each finding against the code before you change anything. The audit can be wrong: if a finding does not hold, tell me why and leave that code alone.
4. Fix one finding at a time. Show me the change as a small diff and apply it only after I say yes.
5. Prove each fix with the measure-loop skill: a before and after on the same scenario. Ask me before running anything that sends real, billed requests.
6. When a fix is proved, set "fixed": true on its finding in .leanprompt/findings.json and run npx leanprompt@0.1.0-dev.15 score.
Findings, largest first:
1. LP-GE-06 at docs/automated-sync.md:41: The documented nightly job runs tools/ingest.py on every .md file under raw/ every night, whether or not the file changed since it was last ingested. Each run is a full ingest call.
2. LP-GE-14 at tools/refresh.py:147: refresh.py compares a 16-character hash (line 72) with the hash it stores after a refresh, which is the full 64-character hash (line 147). They never match, so every plain run re-ingests every source page that has a source_file, as if all were stale.
3. LP-PC-01 at tools/_utils.py:69: Every call goes through one helper that sends a single user message with no cache mark. The tools default to Anthropic models, and Anthropic only reuses a prompt that carries a mark, so batch ingests resend the 2,000-token schema in full each time.
4. LP-GE-05 at tools/ingest.py:241: Ingest asks for one JSON object holding the full source page, the full rewritten overview and every entity and concept page, capped at 8,192 output tokens. When the answer stops at the cap the JSON is cut off, parsing fails, the whole answer is discarded and the program exits; the next run (or the nightly job) sends the same request with the same cap.
5. LP-GE-14 at tools/heal.py:35: heal.py saves a page for a missing entity such as [[Andrej Karpathy]] as entities/Andrej_Karpathy.md, because sanitize_filename turns spaces into underscores. The missing-entity check compares the link text with file names as they are, so the entity is still missing next time and is generated again on every run.
6. LP-GE-05 at tools/build_graph.py:272: Edge inference is capped at 1,024 output tokens. A page with many relationships gets a cut-off JSON, which fails to parse; the page is not checkpointed, so every later build sends the same request with the same cap and fails the same way.
7. LP-GE-10 at tools/ingest.py:222: Ingest asks for JSON in the prompt text only and parses it with regular expressions. An answer with a stray quote or prose around it is discarded and the program exits.
Open questions (confirm before fixing):
- LP-PC-02 (tools/build_graph.py:238): In the relationship-inference loop, each prompt starts with the page being analysed and only then lists all wiki pages, the extracted edges and the rules, which are the same for every page in the run. The shared part comes after the part that changes, so no provider can reuse it. To confirm: which provider and model the graph build runs on: OpenAI or Gemini automatic caching, or Anthropic with a cache mark and a model whose minimum cacheable size is at or below the shared part (about 2,750 tokens for 200 pages)
Other problems found (check each against the code first; not scored):
- A healed multi-word entity is still missing, so its links stay broken (tools/lint.py:76): heal.py saves [[Andrej Karpathy]] as entities/Andrej_Karpathy.md (sanitize_filename joins words with underscores, heal.py:35, since PR #56). find_missing_entities compares the link text with file stems unchanged, so 'andrej karpathy' never matches 'andrej_karpathy': lint keeps listing the entity as missing, keeps telling the user to run heal.py, and the [[links]] stay broken in Obsidian. Change: Keep spaces in the file name (drop the underscore join at heal.py:35; the separator and null-byte removal and the resolved-path check already keep the file inside wiki/entities/).
- The default models are retired, so every tool fails unless LLM_MODEL is set (tools/_utils.py:50) [LP-GE-13]: call_llm defaults to claude-3-5-sonnet-latest and heal, query and build_graph default to claude-3-5-haiku-latest (heal.py:89, query.py:100, build_graph.py:272). Anthropic retired Sonnet 3.5 on 2025-10-28 and Haiku 3.5 on 2026-02-19; requests to retired models return 404. README.md:296 says the scripts need only ANTHROPIC_API_KEY. Change: Default to current models, for example claude-sonnet-4-6 and claude-haiku-4-5, and document LLM_MODEL and LLM_MODEL_FAST in the README.
- An ingest failure ends a whole refresh run and its progress is not saved (tools/refresh.py:91): ingest() calls sys.exit(1) on a parse failure (ingest.py:248). refresh_page catches only Exception, and SystemExit is not one, so the loop stops and save_refresh_cache (line 152) never runs; sources already refreshed in that run are refreshed again next time. Change: Have ingest raise an exception instead of exiting (and exit only in __main__), or catch SystemExit in refresh_page; save the cache after each page.
- One bad answer stops a batch ingest (tools/ingest.py:248): In batch mode (directory or several files, lines 398-399) a single parse failure calls sys.exit(1), so the remaining files are never ingested and the nightly log shows only the first failure. Change: Raise from ingest() and let the batch loop log the failure and continue.
- Edge inference is told the edges listed come from this page, but gets the first 30 of the whole wiki (tools/build_graph.py:229): existing_edge_summary is the first 30 extracted edges of all pages, built once, and the prompt labels it 'Already-extracted edges from this page'. The model cannot avoid repeating this page's own wikilinks, and about 450 tokens of unrelated edges ride on every call. Change: Build the summary per page from the edges whose 'from' is the current page.
- heal.py ignores LLM_MODEL_FAST (tools/heal.py:89): heal intends the fast model (default haiku) but reads LLM_MODEL, so anyone who sets LLM_MODEL to a large model runs heal on it, unlike query.py:100 and build_graph.py:272, which read LLM_MODEL_FAST. Change: Pass 'LLM_MODEL_FAST' as model_env.
- Cut-off answers are printed and saved as complete (tools/query.py:135) [LP-GE-12]: query answers (4,096 cap) and the lint report (lint.py:298, 3,000 cap) are used without checking the finish reason; with --save a cut-off answer is written to wiki/syntheses and indexed as if whole. Change: Check response.choices[0].finish_reason in call_llm and warn or raise when it is length.
Score
One number from 0 to 100 for how well this app avoids paying for the same tokens twice; higher is better. It is computed from the findings above (static) or from your usage log (measured).
60static
E, prefill reuse
0.57
S, prefix stability
1.00
G, generation waste
0.34
Default shares
0 of 8
Findings scored with severity defaults, not estimates. The fewer, the more the static score says about this app.
A static score is an estimate from the audit's findings, not a measurement.
Scored 2026-11-27 (the date on the machine that ran it).
Questions for the owner
These were not answered during the audit. Until they are, the page shows tokens only and ranks the advice without a priority.
Priority: which matters most for this app, cost, speed or quality (or weights)? Not set, so the advice uses equal weights. Answer with priority: in leanprompt.yaml.
Volume: how many calls does the app make a month? Answer with volume: {calls_per_month: N, source: "..."} in leanprompt.yaml.
Prices: what does each model cost (input, cached input, output per 1M tokens, with the source and the date it was read, and the currency if not US dollars)? Answer with prices: in leanprompt.yaml.
If this helped
If this page saved you some digging, a star or a word to a colleague helps other builders find it.
leanprompt checked how our app calls LLMs and found 7 places where it pays for tokens it doesn't need, about 3M tokens per 1,000 calls, an estimate from the code. It explains each finding in plain English and hands the fixes to your coding agent. It is free, open source, and runs locally: https://github.com/Podwarden/leanprompt
The README badge
The badge needs a public repository on GitHub, GitLab.com or Bitbucket with .leanprompt/score.json committed: shields.io reads the file from there. This repository's remote is not one of those, so there is no snippet to paste.