Skip to content

Repository files navigation

Claude Trip Computer

image

Version 0.13.7 | Changelog

Real-time session analytics and optimization insights for Claude Code. TypeScript-powered with multi-line status display, git integration, tool activity tracking, and efficiency metrics.

License

Quick Setup

Prerequisites

  • Node.js 18+ - Check: node --version (Download)
  • Claude Code - Latest version recommended

Automated Installation (Recommended)

Windows:

# Double-click or run:
install.bat

Linux/macOS:

./install.sh

The installer will:

  • βœ“ Check Node.js version (18+ required)
  • βœ“ Detect and remove old bash-based installations automatically
  • βœ“ Prompt for billing mode (API or Subscription)
  • βœ“ Create configuration files
  • βœ“ Update Claude Code settings
  • βœ“ Create /trip command
  • βœ“ Test the installation

Time: ~2 minutes | Then restart Claude Code

Upgrading from bash version? The installer automatically detects and removes old bash scripts, hooks, and cache files. No manual cleanup needed!

Manual Installation

Click to expand manual setup instructions
  1. Clone repository:

    cd ~/Code  # or your preferred location
    git clone https://github.com/luxsolari/claude-trip-computer
  2. Configure billing mode:

    Create ~/.claude/hooks/.stats-config:

    # Claude Code Session Stats Configuration
    BILLING_MODE="API"  # or "Sub" for subscription
    BILLING_ICON="πŸ’³"   # or "πŸ“…" for subscription
    SAFETY_MARGIN="1.00"  # 1.10 for subscription (10% buffer)
  3. Configure Claude Code status line:

    Edit ~/.claude/settings.json:

    {
      "statusLine": {
        "type": "command",
        "command": "npx -y tsx /full/path/to/claude-trip-computer/src/index.ts"
      }
    }

    Replace /full/path/to/ with your actual path.

  4. Restart Claude Code

Time: ~5 minutes

Need Help?

What You Get

Status Line

Real-time session efficiency metrics in your Claude Code status bar:

Multi-Line Status (v0.13.2):

πŸ’¬ 5 msgs (Opus 4.5) | πŸ”§ 12 tools (2.4/msg) | 🎯 15.3K tok | 🌿 main* | β–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘ 35% | ⚑ 78% cached | πŸ“ 3.1K/msg | ⏱️ 31m | πŸ“ˆ /trip
βœ“ Edit Γ—55 | βœ“ Bash Γ—41 | βœ“ Read Γ—23 | βœ“ Write Γ—8
βœ“ Explore: Explore codebase structure (52s)
β–Έ Fix authentication bug (2/5)

Line 1 - Session Metrics:

  • πŸ’¬ 5 msgs (Opus 4.5) - Message count with current model
  • πŸ”§ 12 tools (2.4/msg) - Tool usage with intensity ratio
  • 🎯 15.3K tok - Total tokens (deduplicated)
  • 🌿 main* - Git branch with dirty indicator (NEW)
  • β–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘ 35% - Context window usage bar
  • ⚑ 78% cached - Cache efficiency
  • πŸ“ 3.1K/msg - Response verbosity
  • ⏱️ 31m - Session duration (NEW)
  • πŸ“ˆ /trip - Trip computer link
  • πŸ“… ~$X.XX value (Sub users only) - API-equivalent value

Line 2 - Tool Activity (NEW):

  • Top 5 tools by frequency with accurate session-wide counts
  • Running tools: ◐ Bash: command...

Lines 3+ - Agent Status (NEW, when agents exist):

  • Shows running/completed agents with duration

Final Line - Todo Progress (NEW, when todos exist):

  • In progress: β–Έ Task name (2/5)
  • Complete: βœ“ All todos complete (5/5)

Trip Computer

Ask Claude to show trip computer stats, or run directly:

npx tsx /path/to/claude-trip-computer/src/index.ts --trip-computer

Session optimization dashboard with complete billing-mode differentiation:

For API Users - Optimization-First Experience:

═══════════════════════════════════════════════════════════════
  πŸ“Š TRIP COMPUTER - Session Analytics Dashboard
═══════════════════════════════════════════════════════════════

πŸ“Š QUICK SUMMARY
───────────────────────────────────────────────────────────────
  Health: ⭐⭐⭐⭐⭐ Excellent (85/100)
  Messages: 3 | Tools: 46 | Tokens: 3.8M

πŸ“ˆ SESSION HEALTH (0-100)
───────────────────────────────────────────────────────────────
  Overall: ⭐⭐⭐⭐⭐ 85/100

  ⚑ Cache Efficiency: βœ… 40/40 points
     90% cache hit rate

  βš™οΈ  Context Management: ➑️ 15/30 points
     Context tracking unavailable

  🎯 Efficiency: βœ… 30/30 points
     15.3 tools/msg, 4.4K tok/msg

πŸ€– MODEL MIX
───────────────────────────────────────────────────────────────
  Sonnet 4.5
  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘ 92.7% of cost
  Tokens: 3.5M

  Haiku 4.5
  β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ 7.3% of cost
  Tokens: 336.7K

πŸ“Š TOKEN DISTRIBUTION
───────────────────────────────────────────────────────────────
  Input: 0.1% β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘
  Output: 0.3% β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘
  Cache writes: 9.6% β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘
  Cache reads: 90.0% β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘

⚑ EFFICIENCY METRICS
───────────────────────────────────────────────────────────────
  Tool Intensity: Minimal - early session or simple tasks
    46 tools (15.3 tools/msg) across 3 msgs

  Response Verbosity: Concise - brief responses
    4.4K tokens/msg average

  Output/Input Ratio: 3.13x

  Cache Hit Rate: 90.4%
    Excellent β†’ stay in session

πŸ“Š SESSION METRICS
───────────────────────────────────────────────────────────────
  Messages: 3 | Tools: 46
  Cache Efficiency: 90.4%
  Total Tokens: 3,815,792

  ℹ️  Use /cost for official billing amounts

🎯 TOP OPTIMIZATION ACTIONS
───────────────────────────────────────────────────────────────
  βœ… Session looks well-optimized! Keep up the good work.

πŸ“Š SESSION INSIGHTS
───────────────────────────────────────────────────────────────
  Context Growth: Slow growth β†’ healthy pace
    4.4K tokens/msg average

  Tool Pattern: Minimal - early session or simple tasks
    46 tools (15.3 tools/msg)

  Cache Performance: Excellent β†’ stay in session
    90.4% hit rate

For Subscription Users - Value + Optimization:

  • Same dashboard with πŸ’΅ Cost Drivers (dollar amounts)
  • πŸ“ˆ Trajectory section with projected costs
  • Dollar savings in optimization recommendations
  • API-equivalent estimates with 10% safety margin

How It Works

Technical Implementation

Architecture: TypeScript executed via npx tsx (no compilation needed)

Claude Code Features Used:

  1. Status Line Command (~/.claude/settings.json)

    • Not a hook - direct command execution by Claude Code
    • Invoked automatically on every interaction
    • Receives JSON stdin: {session_id, model, context_window, ...}
    • Returns formatted string to status bar
  2. Custom Slash Command (~/.claude/commands/trip.md)

    • User-invocable skill via /trip
    • Assistant executes command with --trip-computer flag
    • Assistant displays output in code block (instructed by skill docs)
    • No hooks involved - pure command execution
  3. No Hooks Used (v0.11.0+)

    • Old bash version (<0.11.0) used SessionEnd hooks for automatic session-end stats
    • v0.11.0 removed all hooks - uses only status line command + slash command
    • Installer automatically removes old SessionEnd hooks from settings.json

Status Line Flow:

User interaction β†’ Claude Code invokes status line command
β†’ Script reads stdin (session_id, model, context)
β†’ Parses transcript: ~/.claude/projects/<project>/<session>.jsonl
β†’ Deduplicates tokens by requestId + model
β†’ Aggregates per-model, calculates costs
β†’ Returns: "πŸ’¬ X msgs (Model) | πŸ”§ X tools | ..."

Trip Computer Flow:

User types /trip β†’ Assistant invokes skill
β†’ Skill executes: npx tsx src/index.ts --trip-computer
β†’ Same parsing + deduplication + analytics computation
β†’ Outputs dashboard to stdout
β†’ Assistant copies output to response (per skill instructions)

Session Caching:

  • 5-second TTL cache in ~/.claude/session-stats/<session_id>.json
  • Cache invalidated when transcript mtime changes
  • ~10ms cache hits vs ~200ms misses (90% hit rate typical)

Transcript Deduplication Algorithm:

// Group by requestId + model, take MAX tokens per request
const dedupKey = `${requestId}|${modelId}`;
requestUsage.input = Math.max(requestUsage.input, usage.input_tokens);
// Then aggregate into per-model totals

Cross-Project Agent Discovery:

  • Extracts agent IDs from main transcript: /agent-[a-z0-9]+/g
  • Searches all ~/.claude/projects/*/agent-*.jsonl files
  • Includes agent usage in cost calculation (agents are billable)

Zero Dependencies: Uses only Node.js stdlib (no npm install needed)

Features

✨ New in v0.13.0 (Multi-Line Status)

βœ… Multi-line status display - Session metrics + tool activity + agents + todos βœ… Git branch integration - Shows branch name with dirty indicator (🌿 main*) βœ… Session duration - Time since session started (⏱️ 31m) βœ… Tool activity tracking - Top 5 tools by frequency with accurate counts βœ… Agent status display - Running and completed agents with duration βœ… Todo progress - Current task and completion status βœ… Accurate tool counts - Aggregates ALL tools (improvement over claude-hud's last 20)

Session Analytics

βœ… Session health scoring - 0-100 automated assessment with 5-star rating βœ… Model mix visibility - See which models used with cost breakdown βœ… Cost drivers breakdown - Visual analysis of input/output/cache patterns βœ… Efficiency metrics - Tool intensity, response verbosity, cache hit rate βœ… Prioritized recommendations - Top 3 actions ranked by impact βœ… Billing mode differentiation - Adapts for API (πŸ’³) or Subscription (πŸ“…) users

Technical

βœ… Best-effort estimates - Transcript-based calculations typically within 5-15% of /cost βœ… Model-aware pricing - All versions: Opus 3/4/4.5, Sonnet 3.7/4/4.5, Haiku 3/3.5/4.5 βœ… Accurate cache pricing - Model-specific multipliers (including Haiku 3 exception) βœ… Token deduplication - Groups by requestId to avoid inflation βœ… Cross-project agent tracking - Finds agent transcripts across all projects βœ… Real-time updates - Status line refreshes automatically

Why This is Valuable

Speedometer vs. Odometer:

  • Trip Computer = Speedometer (real-time insights for decision making)
  • /cost command = Odometer (authoritative billing from Anthropic)
  • Both are valuable: Use trip computer for session optimization, /cost for billing verification

Immediate Decision Making:

  • "This is getting expensive, let me switch to Haiku"
  • "Cache efficiency is great, stay in this session"
  • "This task used 3.8M tokens - worth tracking"

Cost Awareness:

  • Track session efficiency in real-time
  • Understand which workflows are expensive
  • Learn to use appropriate models
  • Improve cost efficiency over time

Session vs Billing:

  • Trip Computer = Real-time session insights
  • /cost = Final billing verification
  • Both are valuable for complete awareness

Pricing Reference (2026)

Model Input Output Cache Write (5m) Cache Read
Opus 4.5 $5/MTok $25/MTok $6.25/MTok $0.50/MTok
Opus 3/4/4.1 $15/MTok $75/MTok $18.75/MTok $1.50/MTok
Sonnet 3.7/4/4.5 $3/MTok $15/MTok $3.75/MTok $0.30/MTok
Haiku 4.5 $1/MTok $5/MTok $1.25/MTok $0.10/MTok
Haiku 3.5 $0.80/MTok $4/MTok $1/MTok $0.08/MTok
Haiku 3 $0.25/MTok $1.25/MTok $0.30/MTok* $0.03/MTok*

*Haiku 3 uses different cache multipliers: 1.20x for writes, 0.12x for reads

Subscriptions: Pro ($20/mo), Max 5x ($100/mo), Max 20x ($200/mo)

Known Limitations

Context Tracking

Limitation: Context tracking is only available when running as a status line command. Direct execution via bash doesn't receive stdin from Claude Code.

Why: Claude Code only provides stdin data (context_window, model) to processes invoked as status line commands.

Workaround: Use /context command for accurate context information.

Stats Reset with /clear Command

Current Behavior: When you use /clear, stats reset to zero (new session, new transcript).

Why: Each session has its own transcript file for isolation and simplicity.

Desired Future: Cumulative stats across /clear within same Claude Code instance.

Workaround: Note costs before /clear if tracking total spending across resets.

Disclaimer

These are session-level estimates from transcript data, typically accurate within 5-15% of the /cost command. Differences occur due to:

  • Web search costs (may not appear in transcript usage)
  • Background operations
  • Timing variations (transcript lag)
  • API measurement methods

For official billing amounts, always use the /cost command. For subscription users, these show API-equivalent costs - your actual usage is included in your plan.

Technical Architecture

Language: TypeScript with ES2022 modules Runtime: Node.js 18+ (via tsx for direct TS execution) Dependencies: Zero npm packages (stdlib only) Entry Point: src/index.ts Modules: Transcript parser, analytics computer, renderers, cache manager, usage API client Data Flow: stdin β†’ transcript parse β†’ analytics compute β†’ cache β†’ render

Future Enhancements

Potential improvements for future versions:

  • Rate limit display - Show OAuth rate limits in status line (library implemented)
  • Cumulative stats across /clear - Track within same instance, reset on close
  • Cost history tracking - Session-over-session trends
  • Budget alerts - Configurable spending warnings
  • Export stats - CSV/JSON for analysis
  • Time tracking integration - Link sessions to work periods
  • Team analytics - Aggregate across multiple users
  • Custom pricing profiles - User-defined rates
  • Global npm package - npm install -g for source-independent installation
  • Cross-platform Node.js installer - node install.js for pure Windows without Git Bash

Support

Installation issues? Check TROUBLESHOOTING.md

Questions? Review CLAUDE.md for technical details

Want to contribute? See CONTRIBUTING.md

Need help? Verify Node.js 18+ is installed: node --version


Ready to use? Add to ~/.claude/settings.json and restart Claude Code!

About

Real-time cost tracking and advanced analytics for your Claude Code sessions.

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages