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

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

最后的状态样子为:

deepseek-v4-pro[1m] | 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
  }
}
相关推荐
Joseph Cooper3 天前
Claude Code 与 Codex Harness 设计对比:一种加法,一种减法
agent·codex·claudecode·harness
逆境不可逃3 天前
【与我学 ClaudeCode】工具与执行篇:从 0 到 1 拆解 Agent Loop 与 Tool Use 的极简设计哲学
人工智能·学习·agent·claudecode
Soari3 天前
AI 编码智能体的“安全防弹衣”:深度拆解 agent-skills,构建百分百受信任的专业技能注册表
人工智能·网络安全·github·软件工程·aiagent·claudecode·agent-skills
您^_^4 天前
专家(二):Claude Code 数据工程实战:dbt + Airflow + Spark 全流程,$0.22 搭完电商分析管道
大数据·分布式·spark·claudecode·claude code全栈
Rubin智造社4 天前
Claude Code开发者大会系列5:如何打造“AI原生工程师”文化
人工智能·开发者大会·ai 原生·claudecode
深念Y4 天前
正在阅读正在阅读MiMo 突然不能用 Claude Code 了?
ai·api·agent·key·mimo·claudecode·xiaomi
Finger#0000FF6 天前
从零上手VibeCoding(ClaudeCode+DeepSeek V4.Pro)
java·人工智能·ai编程·vibe coding·claudecode
YoungHong19927 天前
Pi Coding Agent : AI时代的“VSCode“
ide·人工智能·gpt·claude·claudecode
Soari7 天前
科研与工程的 AI 助推器:深度拆解 scientific-agent-skills,为你的智能体注入专家级灵魂
人工智能·数据分析·科学计算·科研工具·aiagent·claudecode·ai技能库