Expose session token usage and spend via an MCP tool or context injection
還沒有人認領這個 Issue。
評估
- 難度
- 5/5
- 預估耗時
- 一週以上
- 新手友好度
- 35/100
- Issue 類型
- 功能
- 描述清晰度
- 需要釐清
- 活躍度
- 冷清
- 領域
- cli
研究方向
先追蹤現有的 /context 和 /usage 斜線命令進入點,查看工作階段權杖、內容視窗、credits 和支出指標在哪裡計算。檢查 ~/.commandcode/projects/*.jsonl 中的工作階段逐字記錄和 history.jsonl,以確認目前持久化了哪些中繼資料。定義一條實作路徑,並驗證模型無需使用者複製貼上即可取得準確的目前工作階段用量和 USD 支出。
由索引模型根據 Issue 內容生成。
描述
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:
- 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.
- Injecting the data into the session context (system prompt or environment variable) so it's always available to the model.
- 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
貢獻指南
這個儲存庫沒有索引到貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
CommandCodeAI/command-code 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 68/100
CommandCodeAI/command-code#855 ·
-
難度 2/5 1-3 小時 新手友好度 78/100
CommandCodeAI/command-code#841 · 1 則留言 ·
-
難度 2/5 1-3 小時 新手友好度 68/100
CommandCodeAI/command-code#655 · 1 則留言 ·
-
難度 2/5 1-3 小時 新手友好度 68/100
CommandCodeAI/command-code#608 ·
-
難度 3/5 1-2 天 新手友好度 70/100
CommandCodeAI/command-code#893 ·
查看 CommandCodeAI/command-code 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 86/100
kwakseongjae/auto-hwp#319 ·
-
area:cli bug filter-quality good first issue priority:medium
難度 2/5 1-3 小時 新手友好度 84/100
-
難度 2/5 1-3 小時 新手友好度 76/100
-
難度 2/5 1-3 小時 新手友好度 78/100
AvengeMedia/DankMaterialShell#3523 ·
-
comp/cli comp/cron P3 type/bug
難度 2/5 1-3 小時 新手友好度 76/100
NousResearch/hermes-agent#117433 · 2 則留言 ·