Skip to content

feat(tui): add session statistics display (cost, tokens, cache rate, context usage) #805

@JeremyDev87

Description

@JeremyDev87

Purpose

Display real-time session statistics in the codingbuddy TUI status bar, similar to OMC's status line. Users should see cost, token usage, cache hit rate, and context window utilization at a glance without needing OMC installed.

Reference: OMC Status Line

[OMC#4.2.7] | session:173m | 🔴 | ~$0.6346 | 419.9k | Cache: 99.9% | $0.22/h | ctx:42%

Target Display

[CB] | session:173m | ~$0.63 | 419.9k tokens | Cache: 99.9% | $0.22/h | ctx:42%

Data Points

Metric Description Data Source
session Session elapsed time MCP server start timestamp
cost Estimated cumulative cost Token count × model pricing
tokens Cumulative token usage Track from MCP tool call context
cache Prompt cache hit rate cache_read vs cache_creation tokens
$/h Cost per hour cost ÷ session hours
ctx Context window usage % Current tokens ÷ model max context

Technical Investigation Needed

Data Collection Approaches

  1. MCP server self-tracking — Count tool calls, estimate tokens from request/response sizes
  2. Claude Code metadata API — Check if Claude Code exposes session stats via API or env vars
  3. Anthropic API usage headersx-ratelimit-* headers provide rate limit info
  4. Hybrid — Combine MCP tracking with any available Claude Code metadata

TUI Implementation

  • Existing TUI: apps/mcp-server/src/tui/ (Ink/React-based)
  • Add status bar component at the bottom of TUI
  • Update interval: every 30 seconds or on each tool call

Changes

  • apps/mcp-server/src/tui/ — New status bar component
  • apps/mcp-server/src/mcp/ — Session statistics tracking service
  • apps/mcp-server/src/ — Token/cost calculation utilities

Acceptance Criteria

  • Session elapsed time displayed
  • Estimated cost displayed (based on token counting)
  • Token count tracked and displayed
  • Cache hit rate calculated and displayed (if data available)
  • Context usage percentage displayed (if data available)
  • Cost per hour calculated
  • Updates in real-time (or near real-time)
  • Works without OMC installed
  • TUI tests updated

References

  • OMC status line implementation (inspiration, not copy)
  • codingbuddy TUI: apps/mcp-server/src/tui/
  • Anthropic API pricing: per-model token costs
  • Claude Code API: check for session metadata exposure

Metadata

Metadata

Assignees

No one assigned

    Labels

    featpriority:shouldShould Have - 중요하지만 필수는 아님tuiTUI Agent Monitor

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions