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

未關閉
#430 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
5/5
預估耗時
一週以上
新手友好度
35/100
Issue 類型
功能
描述清晰度
需要釐清
活躍度
冷清
領域
cli

研究方向

先追蹤現有的 /context 和 /usage 斜線命令進入點,查看工作階段權杖、內容視窗、credits 和支出指標在哪裡計算。檢查 ~/.commandcode/projects/*.jsonl 中的工作階段逐字記錄和 history.jsonl,以確認目前持久化了哪些中繼資料。定義一條實作路徑,並驗證模型無需使用者複製貼上即可取得準確的目前工作階段用量和 USD 支出。

由索引模型根據 Issue 內容生成。

描述

p2
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

主要語言
沒有語言資料
星號
4k
分支
350
PR 合併指標
30 天內沒有已合併 PR

貢獻指南

這個儲存庫沒有索引到貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

CommandCodeAI/command-code 的其他 Issue

查看 CommandCodeAI/command-code 的全部 Issue

相似的 Issue

更多 CLI Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。