功能

状态栏

查看 Markdown

状态栏是一行可选的信息,用于显示实时会话数据。它可以显示模型、上下文窗口用量、费用,或你提供的脚本的输出。

在全屏视图中,这一行位于快捷键栏上方;在精简模式中,位于 prompt 信息行下方。欢迎界面和全屏子 Agent 视图打开时,状态栏会隐藏。状态栏默认关闭。

配置状态栏

添加 [ui.status_line] 部分到 ~/.grok/config.toml,然后重启 Grok。

type 键用于选择模式。builtin 显示由 Grok 渲染的数值,command 运行你的脚本,disabled 不显示任何内容。

Grok 只会从你自己的配置或管理员管理的配置中读取这一部分。克隆的仓库无法设置状态栏。

内置项目

项目按你列出的顺序显示。过长的值会以省略号截短。

TOML

[ui.status_line]
type = "builtin"
items = ["cwd", "model", "context"]   # default when omitted

默认组合的显示效果例如:my-project │ Grok 4.5 │ 12% ctx

项目说明
cwd当前目录的名称。
model模型的显示名称。
context上下文窗口用量百分比。达到自动压缩阈值时变为琥珀色;如果 Agent 未报告阈值,则在达到 80% 时变色。
cost当前 Grok 进程的费用。低于 $0.005 时隐藏。恢复的会话从恢复时开始累计费用。
turn-timer当前轮次已用时间,超过一秒后显示。
session-name会话名称(如已设置)。

命令脚本

type 设为 command,并将 command 指向脚本路径或内联 shell 命令。开头的 ~/ 会展开为你的主目录。

以下示例使用 POSIX shell,已在 macOS 和 Linux 上测试。command 状态栏尚未在 Windows 上测试。

  1. 保存 ~/.grok/statusline.sh。脚本从标准输入读取 JSON,并输出一行内容。此示例使用 jq

    Bash

    #!/bin/sh
    payload=$(cat)
    model=$(printf '%s' "$payload" | jq -r '.model.display_name // "?"')
    ctx=$(printf '%s' "$payload" | jq -r '.context_window.used_percentage // 0')
    printf '%s │ %s%% ctx\n' "$model" "$ctx"
  2. 运行 chmod +x ~/.grok/statusline.sh。没有执行权限的文件会显示 [status line: could not start the script: …]

  3. 设置命令:

    TOML

    [ui.status_line]
    type = "command"
    command = "~/.grok/statusline.sh"
  4. 重启 Grok。会话处于活动状态后,这一行就会出现。

脚本通过标准输入接收一个 JSON 对象。常用字段包括 model.display_namecontext_window.used_percentageworkspace.branchcwd。Grok 会省略无法确定的字段。请为缺失的键设置保护措施(例如 jq 中的 // "?")。

会话空闲时不会重新运行脚本。设置 refresh_interval(秒)可让 command 模式也按定时器运行脚本。该键在 builtindisabled 模式下不起作用,但 grok inspect 仍会报告它。

配置前先测试脚本:

Bash

~/.grok/statusline.sh <<'JSON'
{"workspace": {"current_dir": "/tmp/demo", "branch": "main"}, "model": {"display_name": "Grok 4.5"}}
JSON

禁用状态栏

type 设为 disabledoffnonehidden 的含义相同。删除 [ui.status_line] 部分也会禁用这一行。

故障排查

Grok 在启动时读取 [ui.status_line]。编辑 config.toml 后请重启 Grok。

grok inspect 会列出该配置部分的问题。以 [ui.status_line] 开头的行会指出 Grok 无法读取的键。

脚本没有输出且执行失败时,会显示 [status line: exit N]。超时显示 [status line: timed out],被终止显示 [status line: killed by signal],启动失败(包括缺少执行权限)显示 [status line: could not start the script: …]。标准错误不会显示在状态栏中;使用 --debug 运行 Grok 可查看它。


最后更新:2026 年 9 月 3 日