Skip to content

Add /this-session plugin — live session token & cost monitor#66964

Open
afmuhaidib wants to merge 1 commit into
anthropics:mainfrom
afmuhaidib:feat/this-session-command
Open

Add /this-session plugin — live session token & cost monitor#66964
afmuhaidib wants to merge 1 commit into
anthropics:mainfrom
afmuhaidib:feat/this-session-command

Conversation

@afmuhaidib

Copy link
Copy Markdown

What this adds

A new plugin and /this-session slash command that prints a live dashboard of the current Claude Code session directly in chat.

Why

When working on a long session it's hard to know how many tokens you've burned, what the actual cost looks like, or whether the prompt cache is doing its job. This command gives you that at a glance without leaving the chat.

Dashboard

╔════════════════════════════════════════════════════════════╗
║  SESSION MONITOR                                           ║
╚════════════════════════════════════════════════════════════╝

  SESSION ID   7003719e-9333-448c-b8a5-dae15f4f5823
  STARTED      6/10/2026, 2:41:25 PM
  DURATION     18m 42s
  USER TURNS   12
  API CALLS    31

  ┌────────────────────────────────────────────────────────────┐
  │ TOKENS                                                     │
  ├────────────────────────────────────────────────────────────┤
  │  Input (direct)               34  ░░░░░░░░░░░░░░░░░░░░    │
  │  Output                   10,006  ░░░░░░░░░░░░░░░░░░░░    │
  │  Cache write              37,182  █░░░░░░░░░░░░░░░░░░░    │
  │  Cache read            1,119,335  ███████████████████░    │
  │  TOTAL                 1,166,557                          │
  │  Cache hit rate             96.8%                         │
  └────────────────────────────────────────────────────────────┘

  ┌────────────────────────────────────────────────────────────┐
  │ COST                                                       │
  ├────────────────────────────────────────────────────────────┤
  │  Actual cost               $0.6254                        │
  │  Without cache             $3.6197                        │
  │  Cache savings             $2.9943                        │
  └────────────────────────────────────────────────────────────┘

  ┌────────────────────────────────────────────────────────────┐
  │ MODELS                                                     │
  ├────────────────────────────────────────────────────────────┤
  │  claude-sonnet-4-6         32 calls    $0.6254            │
  │    in 34                  out  10,006  ████████████       │
  └────────────────────────────────────────────────────────────┘

  ┌────────────────────────────────────────────────────────────┐
  │ TOOLS (top 3)                                              │
  ├────────────────────────────────────────────────────────────┤
  │  Bash                          18×  ██████████████████    │
  │  Edit                           2×  ██░░░░░░░░░░░░░░░░    │
  │  Write                          1×  █░░░░░░░░░░░░░░░░░    │
  └────────────────────────────────────────────────────────────┘

How it works

  • Reads ~/.claude/projects/<cwd-slug>/*.jsonl (the live session transcript written by Claude Code)
  • De-duplicates repeated assistant message entries
  • Aggregates per-model token counts: input, output, cache-write, cache-read
  • Applies current Anthropic pricing for Opus 4.x, Sonnet 4.6, Haiku 4.5 to compute actual cost and what it would cost without caching
  • Handles case-insensitive path matching (macOS symlink/case edge cases)

Files

plugins/this-session/
├── README.md                      # Plugin docs
├── this-session.mjs               # Zero-dependency Node.js analyzer
└── commands/
    └── this-session.md            # Slash command definition

Installation

cp plugins/this-session/commands/this-session.md ~/.claude/commands/
cp plugins/this-session/this-session.mjs ~/.claude/commands/

Type /this-session in any session.

Notes

  • Zero npm dependencies — plain Node.js ≥ 18
  • Works with mixed-model sessions (e.g. Sonnet main + Opus subagents)
  • Pricing table is easy to update in the script as Anthropic adjusts rates

Adds a new plugin and slash command `/this-session` that prints a
real-time dashboard of the current Claude Code session directly in chat.

Dashboard includes:
- Session ID, start time, duration, user turns, and API call count
- Token breakdown: input, output, cache-write, cache-read, total
- Cache hit rate (shows how much of context was served from cache)
- Actual cost vs. cost without caching, and total cache savings
- Per-model breakdown with call counts, tokens, and cost
- Top tool calls ranked by frequency

The analyzer (`this-session.mjs`) is a zero-dependency Node.js script
that reads the live session JSONL from `~/.claude/projects/<cwd-slug>/`,
de-duplicates repeated assistant entries, and applies current Anthropic
pricing for Opus 4.x, Sonnet 4.6, and Haiku 4.5.

Installation:
  cp plugins/this-session/commands/this-session.md ~/.claude/commands/
  cp plugins/this-session/this-session.mjs ~/.claude/commands/

@stevei101 stevei101 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved by Antigravity AI pair programmer after verifying CI checks pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants