feat: cost/token tracking for Claude and Codex sessions#20
Merged
Wintersta7e merged 10 commits intomainfrom Mar 30, 2026
Merged
feat: cost/token tracking for Claude and Codex sessions#20Wintersta7e merged 10 commits intomainfrom
Wintersta7e merged 10 commits intomainfrom
Conversation
Introduces TokenUsage type, ZERO_USAGE constant, LogAdapter interface, formatTokens/formatCost helpers, and createClaudeAdapter/createCodexAdapter factories with 32 passing tests. Co-Authored-By: Rooty
Discovers and tails agent log files via WSL polling, parsing token usage through LogAdapter and pushing cost:update IPC to the renderer. - Discovery phase: polls candidate dirs every 2s for up to 30s - Tailing phase: polls bound file every 3s, handles partial lines and truncation - 12 tests covering bind/unbind/destroy, discovery, tailing, partial lines, truncation, and IPC guard Co-Authored-By: Rooty
Adds per-session token/cost tracking (inputTokens, outputTokens, cacheReadTokens, cacheWriteTokens, totalCostUsd) with setSessionUsage action and cleanup on removeSession. Co-Authored-By: Rooty
- TerminalPane: bind cost tracking after PTY spawn, unbind on session dispose - App.tsx: listen for cost:update IPC events, unbind on all close paths - PaneTopbar: display cost/token badge with hover tooltip breakdown Co-Authored-By: Rooty
bindSession receives Windows paths from renderer (e.g., E:\H\LocalAI). Convert to WSL paths via toWslPath before building Claude log directory slug. Also store projectPath separately from cwd for Claude's project-indexed log structure. Co-Authored-By: Rooty
Codex JSONL uses payload.info.total_token_usage (not payload directly). Model comes from turn_context events, not token_count events. First token_count has info: null (just rate limits) — now skipped. Added gpt-5.3/5.4 to pricing map. Co-Authored-By: Rooty
…default When a session is opened with a specific agent (e.g., Codex on a project whose default is Claude), the topbar now shows the actual agent name instead of always showing the project default. Co-Authored-By: Rooty
Codex input_tokens includes cached_input_tokens as a subset, unlike Claude where input_tokens already excludes cache reads. Badge was showing inflated totals (e.g. 12k for a simple message). Now both adapters report non-cached input only — badge shows meaningful count. Co-Authored-By: Rooty
…e writes Three fixes for Claude cost tracking: - Compute cost from model pricing (Claude JSONL has no costUSD field) with proper cache rates (writes 1.25×, reads 0.1×) - Skip streaming partials (stop_reason: null) to prevent double-counting - Badge now shows inputTokens + cacheWriteTokens + outputTokens so first-turn cache writes (real processing) are visible, not hidden Also adds Zap icon and accent color to cost badge for visibility. Co-Authored-By: Rooty
Token count now includes all types (input + cache read + cache write + output) so it tracks proportionally with cost. No more mismatch where $0.18 sits next to "87 tokens". Co-Authored-By: Rooty
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Key design decisions
input_tokensexcludes cache; Codexinput_tokensincludes cache — adapters normalize both to non-cachedinputTokens, with cache read/write tracked separatelystop_reasonto prevent double-counting