CommandCodeAI / CommandCodeAI/command-code

Expose session token usage and spend via an MCP tool or context injection

Open
#430 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

p2
Dominant language
No language data
Stars
4k
Forks
350
PR merge metrics
No merged PRs in 30d

Description

Feature Description

The current session's token usage and spend in USD are only accessible via the /context and /usage slash commands, which require manual user input. There is no way for the model (agent) to programmatically read these metrics within a session. I propose exposing this data through one of:

  1. An MCP tool the model can call (e.g. get_session_usage) that returns token count, context window percentage, credits used, and spend in USD.
  2. Injecting the data into the session context (system prompt or environment variable) so it's always available to the model.
  3. Persisting token cost alongside each message in session transcripts (~/.commandcode/projects/*.jsonl) so the model can compute it from the history.

This would enable building skills like a "session-insights" agent that answers "how many tokens have we used?" or "what's the spend so far?" on demand.

Use Case

I want to ask "how many tokens have we used in this session?" or "what's the bill so far in USD?" and get an instant answer without having to manually run slash commands and paste output. A skill that surfaces this data would be far more useful if the model can fetch it directly rather than asking the user to type /context and /usage.

Additional Context

The session transcript files (~/.commandcode/projects/users-*/.jsonl) store conversation text and basic metadata (timestamp, source) but no token counts or cost data. The history.jsonl file also lacks this. As a result, the model has zero visibility into usage metrics — it can only ask the user to run slash commands and interpret what they paste back.

How important is this to you?

Important for my workflow

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the existing /context and /usage slash-command entry points to see where session token, context-window, credits, and spend metrics are calculated. Inspect the ~/.commandcode/projects/*.jsonl session transcripts and history.jsonl to confirm which metadata is currently persisted. Define one implementation path and verify that the model can retrieve accurate current-session usage and USD spend without user copy-paste.

Written by the indexing model from the issue text.

Assessment

Domain
cli
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.