Feature: Expose token counts and cost in session/hook lifecycle

Resolved 💬 3 comments Opened Apr 19, 2026 by jerrythomas Closed May 26, 2026

Summary

Plugins and hooks currently have no way to know how many tokens a session consumed or what it cost. This blocks building session analytics, cost dashboards, and quota projection tools.

Use Case

I'm building sensei — an AI-assisted development companion with a desktop observatory that shows developers their session efficiency (FTR, turns, rework rate, token burn rate). The missing piece is token/cost data.

What I want to show:

  • "This session used 24k tokens in / 8k out, cost \$0.35"
  • "At current burn rate, ~3 days of quota remaining"
  • "This mindset adds 12% more tokens but improves quality by 22% — worth it"

What I have today: Session outcomes, turn counts, tool usage — everything except tokens and cost.

Proposed Solutions (any of these would unblock)

Option A: SessionEnd hook (preferred)

A new hook event SessionEnd that fires when a session closes, with payload:

{
  "session_id": "...",
  "tokens_in": 24000,
  "tokens_out": 8000,
  "cost_usd": 0.35,
  "duration_seconds": 720,
  "turn_count": 8
}

Option B: Enrich existing hooks

Add tokens_in, tokens_out fields to the PostToolUse hook payload (cumulative for the session so far).

Option C: Session metadata API

A CLI command or API endpoint: claude session stats that returns token/cost data for the current or most recent session.

Impact

Without token data, any cost-awareness feature in plugins is impossible. This affects:

  • Session cost tracking
  • Quota burn rate projection
  • Cost-per-feature analysis
  • A/B comparison of different prompt strategies
  • Identifying expensive vs efficient approaches

Environment

  • Claude Code CLI
  • macOS / Linux
  • Building a Tauri desktop companion app that queries the daemon

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗