The Claude max-tokens setting can be edited, but no request reads it

Setting that does nothing Reported

An LLM-driven multi-market stock analysis system with news and dashboards; its transports already parse each provider's stop reason.

The mistake: Setting that does nothingSETTINGANTHROPIC_MAX_TOKENS,editable 256 to 8192REQUESTAnalysis sends a fixed 8192;the agent sends noneRESULTNative Anthropic agent callsget 4096No request path reads the settingThe mistake: Setting that does nothingSETTINGANTHROPIC_MAX_TOKENS, editable256 to 8192REQUESTAnalysis sends afixed 8192; theagent sends noneNo request path reads the settingRESULTNative Anthropicagent calls get4096The mistake: Setting that does nothingSETTINGANTHROPIC_MAX_TOKENS, editable256 to 8192REQUESTAnalysis sends a fixed 8192; theagent sends noneNo request path reads the settingRESULTNative Anthropic agent calls get4096

Estimates, not measurements. Every figure on this page is an estimate from reading the code, not a measurement of the app in use.

Repository
ZhuLinsen/daily_stock_analysis 75.4k GitHub stars
Commit audited
88b577e
leanprompt version
0.1.0-dev.15
Audit date
Status
The maintainers have been told about this audit; no response yet.
Maintainers
the issue
How it ran
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.

leanprompt read the code at commit 88b577e and found 0 places where its LLM calls could use fewer tokens, 1 the project already knows about, plus 3 other problems, not scored. Static score: 100 of 100 (an estimate from the findings, leaving out what the project already knows about). The code may have changed since.

Findings

No open findings.

Already known to the project

The project’s own issues, pull requests or docs already cover these, so they are not counted above and are left out of the static score.

  1. LP-GE-05 Retry only retryable errors; never retry a truncation unchanged

    src/analyzer.py:4862 · severity high · saves prefill and generation · costs no tokens today

    What happens. When the first reply is cut off at the fixed 8192 cap, the integrity retry resends the prompt plus the cut-off reply with the same cap, so it can be cut off again.

    The change. Known to the project; not proposed again here.

    Why it helps. The retry pays for the full prompt and the previous output again.

    Already reported. closed PR 2526 (2026-11-14) measured completion_tokens=8192 and an integrity retry that resent the cut-off output with the same cap; the owner asked for a redesign inside report_integrity, not a separate layer https://github.com/ZhuLinsen/daily_stock_analysis/pull/2526

    Estimate not estimated; the project already tracks it

    Assumptions. none

Other problems the audit found

Problems read in the code that cost no tokens of their own, such as a cost meter or an error path. Not scored.

  1. Usage of earlier attempts is never recorded when a retry or fallback runs

    src/analyzer.py:4889 · LP-GE-11 Meter every billed token, cached and unfinished ones too · severity medium

    What happens. analyze() calls the model in a loop (integrity retry), and each pass overwrites llm_usage. persist_llm_usage runs once after the loop, so the first call of a retried report is billed by the provider but never written to llm_usage. The same happens inside _call_litellm_impl: a model whose reply fails the JSON check is dropped, and only the model that finally answers returns its usage. The screening ranker and the vision extractor never persist usage at all.

    The change. Persist usage inside the loop and inside the model fallback, after each call returns, with the call_type already used, so every billed call has a row.

    Why it matters. get_llm_usage_summary (src/storage.py:4636) sums these rows for the usage report, so retries and fallbacks, the most expensive calls, are the ones missing from it.

    To check. Force one integrity retry (REPORT_INTEGRITY_RETRY=1 with a reply missing stop_loss) and check that llm_usage gets two rows for that stock, or one row per fallback model tried.

  2. ANTHROPIC_MAX_TOKENS is documented and editable but no request path reads it

    src/config.py:2295 · LP-GE-17 Send the output cap the owner set, on every path · severity medium

    What happens. The setting is in the settings page (validation 256 to 8192) and docs/full-guide.md:298 calls it the maximum response tokens for Claude. config.anthropic_max_tokens is read nowhere else in src. The analysis call uses the literal 8192 (src/analyzer.py:4784) and the single-agent loop sends no cap at all (src/agent/runner.py:563), so the native Anthropic request falls back to 4096 (src/llm/anthropic_transport.py:465).

    The change. Either send config.anthropic_max_tokens as max_tokens on the Anthropic route (analysis and agent), or remove the field and say in the docs that the cap is fixed.

    Why it matters. The agent's final answer is the same dashboard JSON the analysis call writes, which the maintainers' own PR 2526 measured at 5,900 to 8,800 characters. A fixed 4096 cap on the Anthropic agent route cuts it with no setting that helps.

    To check. Set ANTHROPIC_MAX_TOKENS=2048, run one agent analysis against a stub server and read max_tokens in the request body: today it is absent (or 4096 after the transport default), not 2048.

  3. The agent loop drops the finish reason, so a cut-off answer is a success

    src/agent/llm_adapter.py:1133 · LP-GE-12 Read the finish reason before using an answer · severity medium

    What happens. The transports parse the stop reason into finish_reason (src/llm/anthropic_transport.py:116, src/llm/openai_transport.py:476), but LLMResponse has no field for it. The runner's final-answer branch (src/agent/runner.py:681) returns success=True with whatever text arrived. A reply stopped by the cap, or tool arguments cut mid-JSON (src/agent/llm_adapter.py:1094 falls back to {"raw": ...}), is treated as finished.

    The change. Add finish_reason to LLMResponse and, in the runner, treat length as unfinished: fail the step or retry once with a larger cap instead of returning the text as the final answer.

    Why it matters. Nothing fails: the call succeeds and the report is stored without its last sections.

    To check. Stub a reply with finish_reason length and check that the run reports an unfinished answer instead of success.

The maintainers’ response

No response from the maintainers yet.

How this was made

The llm-call-audit skill read the code and wrote findings.json; nothing was run against the project’s providers. The full audit page is what leanprompt report --html writes from the same findings.

Corrections and takedown: email info@podwarden.com or open an issue.