在Claude Code中添加statusLine状态栏展示大模型,token用量与session信息

有得时候在一个session中对话久了,模型会变笨记不住指令的情况,这个时候需要/compact对话,或者重开一个对话去完成任务,为了方便去查看什么时候需要重开或者/compact,当前有statusLine的功能,可以展示当前session下模型的使用情况,方便我们进行调整。

最后的状态样子为:

deepseek-v4-pro1m | enterprise_entry_ana (master) I █░░░░░░░░░19% | 1155.2k V76.6k tokens

在~/.claude/settings.json中配置下面的内容。

env是你原本的env,我当前用的deepseek作为Claude Code调用的大模型,所以配置如下;

statusLine是需要你配置的内容;

enabledPlugins是配置的skill。

json 复制代码
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.deepseek.com/anthropic",
    "ANTHROPIC_AUTH_TOKEN": "<你的 DeepSeek API Key>",
    "ANTHROPIC_MODEL": "deepseek-v4-pro[1m]",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "deepseek-v4-pro[1m]",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "deepseek-v4-pro[1m]",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "deepseek-v4-flash[1m]",
    "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1",
    "CLAUDE_CODE_EFFORT_LEVEL": "max"
  },
  "statusLine": {
    "type": "command",
    "command": "python3 -c \"\nimport json, sys, os, subprocess\nraw = sys.stdin.read().strip()\nd = json.loads(raw) if raw else {}\nmodel = d.get('model', {}).get('display_name', '?')\ncwd = d.get('cwd', '')\npath = os.path.basename(cwd) if cwd else '?'\nbranch = ''\ntry:\n    r = subprocess.run(['git', '-C', cwd, 'branch', '--show-current'], capture_output=True, text=True, timeout=2)\n    branch = r.stdout.strip()\nexcept:\n    pass\nctx = d.get('context_window', {}).get('used_percentage', 0)\nbar_w = 10\nfilled = int(ctx / 100 * bar_w) if ctx else 0\nbar = '\u2588' * filled + '\u2591' * (bar_w - filled)\ntok_in = d.get('context_window', {}).get('total_input_tokens', 0)\ntok_out = d.get('context_window', {}).get('total_output_tokens', 0)\ndef fmt(n):\n    if n >= 1000:\n        return f'{n/1000:.1f}k'\n    return str(n)\nprint(f'{model} | {path} ({branch}) | {bar} {ctx}% | \u2191{fmt(tok_in)} \u2193{fmt(tok_out)} tokens')\n\""
  },
  "enabledPlugins": {
    "frontend-design@claude-plugins-official": true
  }
}
相关推荐
小七-七牛开发者7 天前
拆解 dsh 系列:从源码和版本变化看 DeepSeek Harness 的设计取舍
ai·大模型·claude·token·工作流·skill·claudecode·ai coding
小七-七牛开发者8 天前
Agent 小知识 | Skill 的设计与生命周期:从工具接口到能力模块
ai·大模型·agent·token·工作流·claudecode·ai coding
小七-七牛开发者9 天前
拆解 DeepSeek Harness:Profile 与 Bundle 如何装配运行时
ai·大模型·agent·token·工作流·claudecode·ai coding
小七-七牛开发者10 天前
61 亿次请求背后:LLM Serving 的 Cache 与调度难题
ai·大模型·agent·token·工作流·claudecode·ai coding
Roadinforest12 天前
Claude Code 架构深度解析:从 Agent Loop 到 Tool、MCP 与 Context
ai·架构·llm·agent·anthropic·claudecode
深念Y13 天前
为什么选 MiniClaude:一个精简开源替代方案的选型过程
ai·开源·开源软件·agent·claude·workflow·claudecode
带刺的坐椅14 天前
SolonCode 的两个"后悔药":重新运行 vs 继续运行
solon·claudecode·soloncode
小七-七牛开发者14 天前
dsh 拆解系列 Vol.01:没有特权内核的 Agent 运行时
ai·大模型·agent·claude·token·工作流·skill·claudecode·ai coding
小七-七牛开发者15 天前
Agent 小知识|Agent 环境工程:部分可观测性、状态转移与执行隔离
ai·大模型·agent·claude·token·工作流·skill·claudecode·ai coding