MoonshotAI / MoonshotAI/kimi-code
[Feature] status_line.command 的 payload 增加本会话 token 用量(花费/余额 footer 需要)
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 7.5k
- Forks
- 1.2k
- Avg merge
- 11h 53m
- Merged PRs (30d)
- 350
Description
TL;DR
想在 footer 显示「本会话花了多少钱 / key 还剩多少钱」,现在只能让自定义脚本自己解析
~/.kimi-code/sessions/.../agents/*/wire.jsonl 里的 usage.record —— 这是内部格式,容易随版本失效。
希望 status_line.command 的 payload 能直接带上已统计好的 token 用量(可选:估算花费)。
背景
#2106 曾请求在 footer 内置显示「会话 token 消耗 + 估算资费」,被标记为 not_planned。理解官方不打算内置这个渲染。
但官方提供了 status_line.command 这个扩展点(用户脚本渲染 footer 第一行),这本应是 #2106 的解法——缺的只是脚本拿不到的数据。
现状
status_line.command 的 stdin payload(v2.0.1 实测)只有:
model / cwd / gitBranch / permissionMode / planMode / contextUsage / contextTokens / maxContextTokens / sessionId / version
没有累计的 input / output / cache token 数。用第三方 OpenAI 兼容 provider(如 DeepSeek)时,
想显示本会话费用只能自己扒会话日志:
{"type":"usage.record","model":"deepseek/deepseek-flash","usage":{"inputOther":879,"output":561,"inputCacheRead":27136,"inputCacheCreation":0}}
外部脚本还得自己处理多 agent 子目录、usageScope: "session" 的重复快照、增量读取等细节,比较脆。
建议
payload 增加一个 usage 对象(字段名示意):
{
"usage": {
"inputTokens": 123456,
"outputTokens": 7890,
"cacheReadTokens": 2345678,
"cacheCreationTokens": 0
}
}
再进一步的话,也可以直接给出估算花费(按用户配置的单价或内置价格表),
这样「花费 / 余额」类 footer 就完全不需要外部数据源了。
参考
- 已有同类 payload 扩展请求:#2477(透传终端宽度)、#2435 / #3231(托管套餐配额)
- 我用外部脚本实现了一版做验证(读本地会话文件 + 后台查余额,实测 ~90ms,远低于 300ms 上限):
DeepSeek V4.1 Flash · 本次会话 ¥1.17 · key 余额 ¥16.40
仓库:https://github.com/qingtuanX/kimi-code-statusline - 相关踩坑:Windows 下
status_line.command的引号解析问题(#3505 / #2332),我用.cmd包装绕过了
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the status_line.command stdin payload generation and the session usage.record data in wire.jsonl. Trace how usage is aggregated across agents and session-scoped snapshots, then determine the payload fields needed for cumulative token totals. Done means the command receives stable usage data without parsing internal session files, with tests covering the new payload.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- cli, developer-experience
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100