在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
  }
}
相关推荐
Flandern11116 天前
从“能跑”到“可运营”:Agent Harness 工程化建设指南
学习·agent·claudecode·harness
逐梦苍穹8 天前
Claude Code 迁移 Codex 实战复盘:基于 15 天本地日志分析使用量、信任成本与失败地图
prompt·claude·codex·claudecode
梦想的颜色10 天前
【AI 速览】2026 硬核横评:Claude Code vs GPT-5.3 Codex 底层架构 / CLI / 工程能力 / 生产落地全维度对比
claudecode·ai 开发工具·gpt codex·大模型代码能力对比·ai 工具选型指南·ai 编程代理横
带刺的坐椅11 天前
SolonCode v2026.7.13 发布:多工作区协同、推理水平可控、子代理任务分组、工程体验再进化
llm·agent·codex·solon-ai·claudecode·opencode
forestsea17 天前
如何使用 Winget 下载 Claude Code 并实现绿色便携安装
windows·claudecode
yubajin19 天前
ClaudeCode本地源码编译、调试、自定义接入大模型实操案例
源码分析·claudecode
yubajin19 天前
Claude Code 本地源码解读——claw-code
源码分析·claudecode
不爱记笔记20 天前
ClaudeCode接入DeepSeek教程!防封号!
人工智能·ai·deepseek·claudecode
程序员徐公22 天前
Claude Code 是怎么悄悄认出中国用户的
claudecode
小七-七牛开发者24 天前
Coding Agent 规则管理:CLAUDE.md、Skills、Hooks、Subagents 到底怎么选?
ai·大模型·agent·claude·token·loop·mcp·claudecode·ai coding