anomalyco / anomalyco/opencode
TUI context usage always shows 0% — model.limit.context is undefined
@kommander is already working on this.
Since Jul 30, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Description
The context usage indicator in the TUI (the progress circle button showing "used" percentage in the right panel) always shows 0%, regardless of how much conversation has occurred.
Root Cause Analysis
The issue is in the build\ function (which computes session context) in the bundled frontend code. The chain is:
-
build\computesusagefrom the model's context limit:const limit = model?.limit.context; // line 130424 usage: limit ? Math.round(total2 / limit * 100) : null // line 130435 -
When
model.limitisundefined(server doesn't return it),limitbecomesundefined,usageis set tonull. -
SessionContextUsagecomponent renders:percentage: context()?.usage ?? 0 // null → 0 -
ProgressCircleshows 0%:const clampedPercentage = Math.max(0, Math.min(100, 0 || 0)); // = 0
Two Possible Causes
-
Server API doesn't return
limit.context— Themodel.limitfield at line 75945 is passed straight through from the server's model list API response (sdk.model.list()). If the server doesn't includelimit: { context: <number> }in the model data,limitisundefined. -
Server doesn't send token data in
session.step.ended— At line 78140,event.data.tokenspopulates the assistant message. If this is empty,tokenTotalreturns 0,lastAssistantWithTokensskips the message, andbuild\returnsundefined→ 0%.
Additional crash risk
The same model.limit is accessed without null safety in ModelTooltip component (line 136394):
props.model.limit.context.toLocaleString() // crashes if model.limit is undefined
Suggested Fix
In build\, add a fallback for model.limit:
const limit = model?.limit?.context ?? 0;
And in ModelTooltip:
props.model.limit?.context?.toLocaleString() ?? "unknown"
But the real fix should be on the server side to ensure model.limit.context is always populated with the correct context window size for each model.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.