CommandCodeAI / CommandCodeAI/command-code
Expose session token usage and spend via an MCP tool or context injection
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Không có dữ liệu ngôn ngữ
- Star
- 4k
- Fork
- 350
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
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
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách lần theo các điểm vào của slash command /context và /usage hiện có để xem token phiên, cửa sổ ngữ cảnh, credit và các chỉ số chi tiêu được tính ở đâu. Kiểm tra các bản ghi phiên và history.jsonl trong ~/.commandcode/projects/*.jsonl để xác nhận những metadata nào hiện đang được lưu bền vững. Xác định một hướng triển khai và xác minh rằng model có thể lấy được thông tin sử dụng chính xác của phiên hiện tại và số tiền chi bằng USD mà không cần người dùng sao chép-dán.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Lĩnh vực
- cli
- Loại issue
- Tính năng
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Cần làm rõ
- Mức phù hợp với người mới
- 35/100