Skip to content

gut(session): remove vestigial contextTokens config and display denominator #2133

@alexey-pelykh

Description

@alexey-pelykh

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    gutRemoving dead upstream subsystems

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions