You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat: add /tokens /context /cost commands to show token usage and context size #224
It would be very useful to have visibility into token consumption and context size directly from the CLI, similar to Claude Code's /context and /cost commands.
Motivation
Currently, Deep Code already stores token usage data internally in sessions-index.json. According to the docs, each session entry tracks:
"token 用量 and 活跃 token 数"
However, there is no way to view this information from the CLI interface. Users have no visibility into:
How many tokens they have consumed in the current session
How much of the context window is being used
What is consuming the most tokens (system prompt, conversation history, skills, MCP tools)
Proposed Commands
/tokens – Show current session token consumption
Displays the token usage breakdown for the current session:
Input tokens (this turn)
Output tokens (this turn)
Thinking tokens (if thinking mode is enabled)
Total tokens (entire session)
Estimated cost (based on model pricing)
/context – Show context window breakdown
Displays what is consuming the context window:
System prompt size (tokens)
Conversation history size (# of messages, tokens)
Skills loaded and their contribution
Active MCP tools and their descriptions size
Total context window usage (e.g., 15K / 128K / 1M)
/cost – Show cumulative session cost
Shows the estimated cost of the current session based on model pricing:
Per-turn cost breakdown
Total session cost
Thinking vs non-thinking token cost
Why This Matters
Cost awareness – Helps users monitor spend when using paid API models (especially with reasoning/thinking tokens which add significant cost)
Debug context limits – When approaching context window limits, users can identify the culprit (bloated history, too many skills, etc.)
Optimization feedback – Allows users to measure the impact of prompt optimization, skill trimming, or MCP cleanup
Parity with alternatives – Tools like Claude Code already offer /context and /cost; adding these would reduce friction for users migrating to or evaluating Deep Code
Implementation Notes
The data already exists in ~/.deepcode/projects/<project-code>/sessions-index.json which stores "token 用量" per session entry
For real-time context window tracking, the token counts could be computed from the messages being sent to the model API
A lightweight tokenizer or cached counts per message would suffice — no need for full tokenization on every request
This is an open-ended feature request. Happy to help with implementation or testing.
Activity
dengmik-commits commentedon Jul 8, 2026
这些信息其实已经可以通过 statusline 插件 实时展示在状态栏中,无需修改 CLI 源码即可实现类似效果(类似我在 #216 回复的做法)。
目前
SessionInfo已经暴露了以下数据供 statusline module provider 使用:totalTokensactiveTokensmaxContextTokensrequestCountmessageCountmodeltoolUsage配置方式
在
.deepcode/settings.json中添加 statusline 配置:{ "statusline": { "enabled": true, "refreshMs": 3000, "providers": [ { "type": "module", "id": "tokens", "path": "./.deepcode/plugins/tokens.mjs", "color": "yellow" } ] } }插件示例
创建
.deepcode/plugins/tokens.mjs:效果:状态栏会实时显示类似
token: 15234 (11.9% ctx) | req: 8 | msg: 42的信息。如果你还想看更详细的 breakdown(system prompt 大小、技能贡献等),也可以写一个更复杂的 module provider 从
sessions-index.json读取更多数据。相关文档可参考 statusline.md。
dengmik-commits commentedon Jul 8, 2026
这样更好,是恒值状态,不必调用命令来显示,一直能直观显示