在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
  }
}
相关推荐
逐梦苍穹13 天前
不训练不微调:直接改权重矩阵,给小模型补上新能力
ai编程·codex·claudecode
小七-七牛开发者14 天前
周 1 上线 | DSH 喜提原神进场动画,Anthropic 启动 IPO 路演;黄仁勋辞任;微软全球大宕机超 24 小时
ai·大模型·agent·token·工作流·claudecode·ai coding
逐梦苍穹16 天前
DeepInfer 推理框架源码精讲:逐行读 DeepSeek 开源的推理引擎(2 小时 20 分视频+文字版)
人工智能·开源·ai编程·deepseek·claudecode·deepinfer·deepseekinfer
meijinmeng21 天前
如何像使用高级工程师一样使用 Claude,而不是像使用聊天机器人一样使用 Claude
claudecode·ai开发工具实战
Florian23 天前
Claude Memory 设计解读:记住经验,保留边界
memory·claudecode·harness·dreaming
信息安全失业大专人员1 个月前
每日了解一个智能体-ClaudeCode
智能体·claudecode
大连好光景1 个月前
Claude Code Agent SDK详解
lsp·hooks·mcp·claudecode·skills·mcp命名规范与调用权限
范中勤2 个月前
缓存 Key 规范与 Claude 动态/静态 Prompt Cache 机制详解
claudecode·promptcache·缓存key·agent工程·动静边界
人生百态,人生如梦2 个月前
Ubuntu在低版本下使用ccswitch+claudecode(CCSwitch+Docker+Claude)连调教程
linux·ubuntu·docker·claudecode·ccswitch
三水写代码2 个月前
手写一个 Claude Code(1):从 Agent Loop 到工具、权限、Hooks 与任务规划
python·ai编程·claude·ai agent·claudecode