Skip to content

feat: Cost analysis page for Codex (~/.codex/sessions) #46

@lis186

Description

@lis186

Problem

The Usage page scans ~/.claude/ JSONL files via cost-worker.js for daily/monthly cost analytics. Codex historical usage under ~/.codex/sessions/ is completely invisible — no historical cost data, no heatmap, no burn rate for Codex sessions.

Scope

  • Extend cost-worker.js (or add a parallel worker) to scan ~/.codex/sessions/ for token_count events
  • Parse last_token_usage.cached_input_tokens and model info from session event files
  • Integrate into the existing cost-budget-ui daily/monthly views
  • Respect normalizeUsageForProvider for correct cost calculation

Before / After UI

BEFORE (Usage page):
+-------------------------------------------------------+
| Usage          Daily | Monthly                         |
+-------------------------------------------------------+
| Heatmap: [Claude sessions only]                       |
|  Jun 01  ██░░  $2.40                                  |
|  Jun 02  ████  $5.10                                  |
|  Jun 03  ██░░  $3.20                                  |
|                                                       |
| Burn Rate: $3.57/day (Claude only)                    |
| ROI Badge: based on Claude costs only                 |
|                                                       |
| Codex usage: (invisible)                              |
+-------------------------------------------------------+

AFTER (Usage page):
+-------------------------------------------------------+
| Usage          Daily | Monthly    [All|Claude|Codex]   |
+-------------------------------------------------------+
| Heatmap: [Both providers, color-coded]                |
|  Jun 01  ██░░ Claude $2.40  ░░░░ Codex $0.00         |
|  Jun 02  ████ Claude $5.10  ██░░ Codex $1.80         |
|  Jun 03  ██░░ Claude $3.20  ████ Codex $4.50         |
|                                                       |
| Burn Rate: $5.67/day (combined)                       |
| ROI Badge: reflects total AI spend                    |
|                                                       |
| Provider toggle filters heatmap + burn rate           |
+-------------------------------------------------------+

Architecture

Current data flow

~/.claude/ JSONL ──> cost-worker.js ──> cost-budget.js ──> cost-budget-ui.js
                    (child process)    (orchestration)      (Usage page)

Proposed addition

~/.claude/ JSONL ────> cost-worker.js ──────┐
                       (child process)      │
                                            v
                                      cost-budget.js ──> cost-budget-ui.js
                                      (merged view)      (Usage page)
                                            ^
~/.codex/sessions/ ──> codex-cost-worker.js │
  event files             (child process) ──┘

Key files:

  • server/cost-worker.js — scanner (runs as child process to avoid blocking event loop)
  • server/cost-budget.js — orchestration, caching, grouping
  • public/cost-budget-ui.js — UI rendering (heatmap, burn rate, ROI)

Codex session format: Event files contain event_msg/token_count with last_token_usage.cached_input_tokens. Need to apply normalizeUsageForProvider for correct cost calculation.

Design note: cost-worker.js runs as a child process to avoid blocking the event loop. The Codex scanner should follow the same pattern — a separate child process (or a second mode in the existing worker).

Value

For users

  • Complete cost visibility across all AI agents in one dashboard
  • Accurate ROI calculation (topbar ROI badge currently only reflects Claude costs)
  • Daily/monthly heatmap includes Codex usage patterns

For developers

Side Effects

  • First scan of ~/.codex/sessions may be slow if many session files exist
  • Monthly cost totals will increase (Codex costs now included) — users may notice jumps
  • ROI badge divisor assumes Claude subscription price; mixed-provider ROI needs thought
  • Privacy: scanning ~/.codex/sessions accesses another tool's local data

Test Plan

  • Unit: Codex session file parsing + cost calculation
  • Smoke: start ccxray with real ~/.codex/sessions data, verify Usage page shows entries
  • Verify: cost numbers match what Codex's own usage monitor tools report

Metadata

Metadata

Assignees

No one assigned

    Labels

    codex-parityCodex dashboard parity gapsenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions