Summary
contextTokens is a static config value used as a display denominator for "Context: 45k / 200k (22%)" in status output. The lookup functions that originally resolved it from model metadata are stubbed out (lookupContextTokens, DEFAULT_CONTEXT_TOKENS), making the denominator a guess (defaults to 200k). The actual token counting (input/output/cache) from CLI runtimes works correctly and should be preserved.
What to Remove
contextTokens field from SessionEntry (src/config/sessions/types.ts)
contextTokens field from AgentDefaultsConfig and AgentConfig (src/config/types.agent-defaults.ts)
contextTokens from Zod schema (src/config/zod-schema.agent-defaults.ts)
contextTokens parameter from deriveSessionTotalTokens() (src/agents/usage.ts) — it accepts it but never reads it
lookupContextTokens stub and DEFAULT_CONTEXT_TOKENS stub in agent-runner.ts
contextTokensUsed resolution chain in agent-runner.ts
contextTokens passthrough in session-store.ts, session-usage.ts, get-reply-run.ts, get-reply-directives.ts, get-reply-directives-apply.ts
contextTokens in cron runner (src/cron/isolated-agent/run.ts:424-428)
- Percentage display logic in
formatTokens() and related formatting (src/auto-reply/status.ts, src/commands/sessions.ts, src/commands/status.summary.ts, src/commands/status.format.ts)
contextTokens from gateway session utils (src/gateway/session-utils.ts)
contextTokens from TUI types and session actions (src/tui/)
contextTokens from UI types and presenter (ui/src/ui/)
What to Keep
totalTokens, inputTokens, outputTokens, cacheRead, cacheWrite in session entries — these are real usage data from CLI runtimes
deriveSessionTotalTokens() function (without the unused contextTokens param)
hasNonzeroUsage() and normalizeUsage() — real usage utilities
- Token display in status, simplified to raw count: "Tokens: 45k" instead of "Context: 45k / 200k (22%)"
Acceptance Criteria
-
Given the codebase
When searching for contextTokens in source files
Then no matches found (except changelog/git history)
-
Given remoteclaw status output
When a session has token usage
Then raw token count is displayed (no percentage against a static denominator)
-
Given agents.defaults.contextTokens in a config file
When the config is loaded
Then the field is silently ignored (Zod strips unknown fields) or explicitly warned
-
pnpm check passes
-
Existing tests pass (or updated to remove contextTokens assertions)
Rationale
The contextTokens denominator is misleading: it defaults to 200k regardless of actual runtime context window (Gemini has 1M, some Claude models have 1M). The stubs (lookupContextTokens → undefined, DEFAULT_CONTEXT_TOKENS → undefined) mean the resolution chain falls through to hardcoded 200k. Removing the misleading percentage is better than displaying an inaccurate one.
If runtime-reported context windows are wanted later (for proactive session health notifications), the token counting infrastructure survives — only the static config denominator is removed.
Depends On
None — independent of the provider ID unification chain (#2125-#2128). Can be executed in parallel.
Summary
contextTokensis a static config value used as a display denominator for "Context: 45k / 200k (22%)" in status output. The lookup functions that originally resolved it from model metadata are stubbed out (lookupContextTokens,DEFAULT_CONTEXT_TOKENS), making the denominator a guess (defaults to 200k). The actual token counting (input/output/cache) from CLI runtimes works correctly and should be preserved.What to Remove
contextTokensfield fromSessionEntry(src/config/sessions/types.ts)contextTokensfield fromAgentDefaultsConfigandAgentConfig(src/config/types.agent-defaults.ts)contextTokensfrom Zod schema (src/config/zod-schema.agent-defaults.ts)contextTokensparameter fromderiveSessionTotalTokens()(src/agents/usage.ts) — it accepts it but never reads itlookupContextTokensstub andDEFAULT_CONTEXT_TOKENSstub inagent-runner.tscontextTokensUsedresolution chain inagent-runner.tscontextTokenspassthrough insession-store.ts,session-usage.ts,get-reply-run.ts,get-reply-directives.ts,get-reply-directives-apply.tscontextTokensin cron runner (src/cron/isolated-agent/run.ts:424-428)formatTokens()and related formatting (src/auto-reply/status.ts,src/commands/sessions.ts,src/commands/status.summary.ts,src/commands/status.format.ts)contextTokensfrom gateway session utils (src/gateway/session-utils.ts)contextTokensfrom TUI types and session actions (src/tui/)contextTokensfrom UI types and presenter (ui/src/ui/)What to Keep
totalTokens,inputTokens,outputTokens,cacheRead,cacheWritein session entries — these are real usage data from CLI runtimesderiveSessionTotalTokens()function (without the unusedcontextTokensparam)hasNonzeroUsage()andnormalizeUsage()— real usage utilitiesAcceptance Criteria
Given the codebase
When searching for
contextTokensin source filesThen no matches found (except changelog/git history)
Given
remoteclaw statusoutputWhen a session has token usage
Then raw token count is displayed (no percentage against a static denominator)
Given
agents.defaults.contextTokensin a config fileWhen the config is loaded
Then the field is silently ignored (Zod strips unknown fields) or explicitly warned
pnpm checkpassesExisting tests pass (or updated to remove contextTokens assertions)
Rationale
The
contextTokensdenominator is misleading: it defaults to 200k regardless of actual runtime context window (Gemini has 1M, some Claude models have 1M). The stubs (lookupContextTokens → undefined,DEFAULT_CONTEXT_TOKENS → undefined) mean the resolution chain falls through to hardcoded 200k. Removing the misleading percentage is better than displaying an inaccurate one.If runtime-reported context windows are wanted later (for proactive session health notifications), the token counting infrastructure survives — only the static config denominator is removed.
Depends On
None — independent of the provider ID unification chain (#2125-#2128). Can be executed in parallel.