图文实操教程

Claude Code 状态栏(Statusline)设置教程:一条 /statusline 命令搞定

跟着真实 Windows 录屏,一步步开启 Claude Code 状态栏:运行 /statusline、选全新默认方案、批准生成的 statusline-command.sh 脚本,看懂底部那行「用户名 · 目录 · 分支 · 模型 · 上下文用量」。

Claude Code terminal confirming Your status line is configured with a sample harddik | ~/Dvs/project | main | Claude Opus 4.6 | ctx:42% status line and an explanation of the username, directory, branch, model and context window segments
录屏里的「Your status line is configured!」确认页——示例状态行(harddik | ~/Dvs/project | main | Claude Opus 4.6 | ctx:42%)和逐段说明,录制于 2026 年 3 月。

约 5 分钟 · 13 个图文步骤

太长不看版

启动 claude,输入 /statusline,回答设置问题即可。Windows 上找不到 shell 配置文件,所以选项 3(全新默认状态栏)最快:它会生成 ~/.claude/statusline-command.sh、更新 ~/.claude/settings.json,并在终端底部显示用户名、当前目录、Git 分支、模型和上下文用量。弹出 diff 审批时选同意,之后想改随时让 Claude「更新状态栏」。

关于来源视频

本页每一帧画面都来自 ProgrammingKnowledge2 的录屏——Windows 上 D:\Dev 目录里的 Claude Code v2.1.83 会话(Opus 4.6 · 1M 上下文 · Claude Max),录制于 2026 年 3 月。

截图经署名使用,每一步都链回视频的精确秒数。旁白没有照抄——上文根据画面内容撰写,并已与 code.claude.com/docs 核对。

在终端里打开 Claude Code

整个过程只需要一个 PowerShell 窗口,不需要编辑器或任何面板。

  1. 1

    启动 CLI

    打开 Windows PowerShell(任何终端都行,录屏用的是 PowerShell),cd 进项目目录,输入 claude 回车,CLI 就在该目录里启动了。

    Windows PowerShell window with the claude command typed at the PS D:\Dev> prompt to launch the Claude Code CLI
    在 PowerShell 提示符里输入 claude 启动命令(D:\Dev 目录)。看视频 0:18 处
  2. 2

    欢迎框

    Claude Code 会先弹出欢迎框,显示版本(录屏里是 v2.1.83)、套餐和当前模型——Claude Max 账号上的 Opus 4.6、1M 上下文窗口。接下来的一切都发生在这个终端会话里。

    Claude Code v2.1.83 welcome box in a Windows terminal showing Welcome back DRIS!, the Opus 4.6 1M context window model line and the Claude Max plan for the D:\Dev project
    Claude Code v2.1.83 会话在 Claude Max 套餐下的 D:\Dev 目录启动。看视频 0:22 处

运行 /statusline 命令

一条斜杠命令,把任务交给专门的设置代理。

  1. 3

    输入斜杠命令

    在输入框里输入 /statusline。自动补全菜单里能看到两个相关命令:/statusline——「Set up Claude Code's status line UI」,以及 /status,后者按需打印版本、模型、账号、API 连接和工具状态。提交 /statusline。

    Claude Code slash command autocomplete menu listing /statusline to set up the status line UI next to /status which shows version, model, account, API connectivity and tool statuses
    自动补全菜单里的 /statusline 条目,上方紧挨着 /status。看视频 0:32 处
  2. 4

    设置代理接管

    提交 /statusline 并不只是切换一个开关——它会启动一个小的设置代理(statusline-setup,「Configure statusline from PS1」),根据你的 shell 和平台决定怎么配置。你会看到它以 Initializing 转圈开始干活。

    Claude Code terminal right after /statusline is submitted with the statusline-setup Configure statusline from PS1 tool call highlighted and an Initializing spinner below it
    命令提交后立刻转起来的 statusline-setup 代理。看视频 0:42 处

回答设置问题

Windows 没有 shell 提示符配置可转换——全新默认方案最快。

  1. 5

    先找现成的 PS1

    代理会先找你 shell 的提示符定义,读取 C:\Users\<用户名>\.bashrc、.bash_profile 之类的文件,看有没有可以直接转换的 PS1。这台 Windows 机器上没有。

    statusline-setup tool output in Claude Code showing Read calls on C:\Users\drisa\.bashrc and .bash_profile while it searches for an existing PS1 prompt definition
    代理在 .bashrc 和 .bash_profile 里搜寻 PS1 的 Read 调用记录。看视频 0:52 处
  2. 6

    三条路

    在 Windows 上,代理报告「couldn't find standard shell config files」,给出三个选项:1. 粘贴你的 PS1 让它转换;2. 指向自定义位置的配置文件,比如 WSL 或 Git Bash;3. 全新配一条状态栏——「sensible default showing user, directory, model, and context usage」。

    Claude Code reply on Windows saying the agent couldn't find standard shell config files with three numbered options to paste a PS1, point to a WSL or Git Bash config, or set up a fresh statusline showing user, directory, model and context usage
    Windows 上没找到 shell 配置后的提问——三个编号选项。看视频 1:02 处
  3. 7

    选全新方案

    视频作者输入 3。全新默认路线不依赖你现有的 shell 提示符,是 Windows 上最快的路径——在 macOS 和 Linux 上不想翻译 PS1 的话,同样可以这么选。

    Claude Code input box with the answer 3 typed beneath the three statusline setup options to request the fresh default statusline
    输入 3,要求配置全新默认状态栏。看视频 1:24 处
  4. 8

    生成默认配置

    拿到答复后,statusline-setup 代理把任务改标为「Setup fresh default statusline」开始配置——动手之前先读取你现有的 ~/.claude/settings.json。

    Claude Code statusline-setup tool switching to Setup fresh default statusline with Initializing and Configuring spinners after option 3 is confirmed
    确认选项 3 后,Setup fresh default statusline 开始运行。看视频 1:48 处

检查并批准生成的脚本

动你的设置之前,Claude 会把完整 diff 摆给你看。

  1. 9

    批准 diff

    Claude 会把要写入的内容完整亮出来:一个小 bash 脚本,把状态 JSON 用 jq 解析出上下文窗口百分比、git 分支和模型名,再用 printf 拼成一行。对话框问「Do you want to make this edit to statusline-command.sh?」——作者选了选项 2「Yes, and allow Claude to edit its own settings for this session」,之后再改就不用重新审批。

    Green added-lines diff of the generated statusline-command.sh bash script in Claude Code above the Do you want to make this edit approval dialog with Yes, Yes and allow further edits, and No choices
    生成的 statusline-command.sh diff 和它的审批对话框。看视频 2:10 处
  2. 10

    写了哪些文件

    批准后,工具的动作列表显示两个落点:创建 ~/.claude/statusline-command.sh(渲染状态行的脚本),更新 ~/.claude/settings.json(让 Claude Code 运行它的配置项)。

    statusline-setup tool in Claude Code listing Create C:\Users\drisa\.claude\statusline-command.sh and Update settings.json actions after the edit was approved
    工具动作列表里的 Create statusline-command.sh 和 Update settings.json。看视频 2:22 处

确认状态栏生效

状态栏直接出现在同一个终端底部,并给出日后自定义所需的两个路径。

  1. 11

    49 秒收工

    这一轮以「Done (5 tool uses · 6.4k tokens · 49s)」结束。注意终端底边:还没等代理把话说完,新状态栏已经实打实显示在那里了——harddik | d:/Dev。

    Claude Code showing the statusline-setup result Done (5 tool uses, 6.4k tokens, 49s) with a Refining spinner while the new harddik | D:/Dev status line already renders at the bottom of the terminal
    工具调用收尾,底部已经渲染出真正的状态行。看视频 2:48 处
  2. 12

    每一段是什么

    确认信息给出了示例和图例——harddik | ~/Dvs/project | main | Claude Opus 4.6 | ctx:42%:依次是用户名、当前目录(缩短显示)、在 Git 仓库里时的分支名、当前模型,以及上下文窗口用量。

    Claude Code confirmation reading Your status line is configured with a sample harddik | ~/Dvs/project | main | Claude Opus 4.6 | ctx:42% line and a five-item legend explaining the username, directory, branch, model and context segments
    「Your status line is configured!」——示例状态行和五段图例。看视频 3:06 处
  3. 13

    配置在哪

    记住两个路径:配置在 ~/.claude/settings.json,脚本在 ~/.claude/statusline-command.sh。以后想改显示内容,直接让 Claude「update the status line」就行,不用手动编辑。

    Claude Code session summary stating the config lives in ~/.claude/settings.json with the script at ~/.claude/statusline-command.sh, above the rendered harddik | d:/Dev status line at the bottom of the terminal
    最终总结点出两个文件路径,底部是已生效的状态行。看视频 3:12 处

常见问题