← Catalog

@aoshizuku/pi-hud

Claude HUD-style three-line statusline for pi: model, context, tokens, tools

Extension

Install

Install with PiG

pig install npm:@aoshizuku/pi-hud

Install with Pi

pi install npm:@aoshizuku/pi-hud
Review before installing

Packages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.

Pi manifest JSON

The pi field of package.json.

{
  "extensions": [
    "./src/index.ts"
  ]
}

README

Written by the package's publisher, shown as published in version 0.1.1 (README.md). PiG does not review it.

pi-hud

给 pi 用的 Claude HUD 风格三行状态栏。个人信息密度优先,不做配置化。

[deepseek/deepseek-flash | max] | demo-app git:(main)
Context ███░░░░░░░ 25% (1M) | 200 tps · 30.0M token used · ↑Out 109 · ↓Input 3 · Cache Create 1.7K · Cache Read 31.6K
✓ Read ×1

三行分别是什么

  1. 模型行:[provider/model | thinking level]、当前目录名、git 分支;装了 pi-background-shell 且有后台任务在跑时,末尾追加 | 1 shell / | 2 shells。
  2. 上下文与用量行:
    • context 进度条 + 百分比 + 上下文窗口大小;
    • 本轮输出速度(tps);
    • 本会话累计 token;
    • 本轮 ↑Out / ↓Input / Cache Create / Cache Read。 每一项为 0 时自动隐藏。终端变窄时按四步降级:先隐藏 Cache Create / Cache Read 文字(只留图标和数值),再隐藏 token used / Out / Input 文字,然后 | 右侧只留 tps 和总 token,最后从右往左丢掉 tps 和总量。
  3. 工具行:正在运行的工具(最多 2 个)和已完成工具的计数(最多 4 组)。

装了 pi-subagent 时,第二行多一段 agents 120K(子 agent 累计的 input + output + cache write,不并入会话总量), 工具行下面多出 agent 行(claude-hud 风格):

● explore [flash]: 查找鉴权相关代码 (1m 12s · turn 4)
◌ explore: 检查迁移脚本 (queued)
✓ general: 统计配置项 (48s)
… +2 more agents
  • 显示哪些行、什么顺序由 pi-subagent 决定(运行中、排队中、60 秒内结束的,最多 4 行);pi-hud 只负责画。没有 agent 时不占高度。
  • [flash] 只在子 agent 的模型和主会话不同时出现。终端变窄时先截 description(最少留 12 列),再截整行。
  • 有运行中的行时每秒重绘一次(时长在走),没有时不开定时器。
  • pi-subagent 的键盘选择模式(编辑器为空时按 ↓)下,选中行左栏出现 accent 竖标 ▎、整行铺上主题的选中底色(和 /agents、/background 列表一样),底部多一行 ↑↓ select · enter view · x stop · esc back。 按下第一次 x 后选中行进入确认态:竖标变成 error 色、底色换成主题的错误底色(toolErrorBg),提示行换成 error 色的 press x again to stop · any other key cancels。
  • 全屏模式下点击 agent 行打开它的详情浮层,点击 +N more 打开列表;点击模型行末尾的 N shells 打开 /background 列表。前三行其他位置不处理(照常选择文字)。普通模式下鼠标归终端,点击不生效。

安装

安装:

pi install npm:@aoshizuku/pi-hud                # 从 npm 安装
pi install git:github.com/AoShizuku/pi-hud     # 或从 GitHub 安装

本地路径安装(clone 之后):

pi install ./pi-hud

只试一次:

pi -e ./pi-hud/src/index.ts

安装后启动 pi 即生效。/hud 切换开关,/hud on / /hud off 显式设置。开关写进 ~/.pi/agent/pi-hud.json,重启后保持;也可以在 /shizuku 设置面板里改。

数据来源

全部走 pi 的一等 API,不跑 git 子进程:

内容来源
provider / modelctx.model
thinking levelpi.getThinkingLevel()(仅 reasoning 模型)
目录名ctx.cwd 的 basename
分支footerData.getGitBranch()(pi 内部监听 .git/HEAD)
contextctx.getContextUsage(),按 leaf 缓存,避免每帧重算
会话累计 tokenctx.sessionManager.getBranch() 里的 assistant usage,按 leaf 缓存
本轮 token / tps本次进程最后一条完成的 assistant 响应(message_end)
工具活动tool_execution_start / tool_execution_end;启动/恢复/切分支时从 branch 的 toolResult 重建
后台 shell 数pi.events 的 bg:state(pi-background-shell 发布);订阅后发一次 bg:state:request 拿当前值,没装该插件时不显示。点击 N shells 时发 bg:open
agent 行、agents 用量pi.events 的 subagent:state(pi-subagent 发布);订阅后发一次 subagent:state:request。pi-hud 反过来在挂上 / 卸下 footer 时发 subagent:hud { rendering }(收到 subagent:hud:request 时重发),点击 agent 行时发 subagent:open { agentId? }。协议见 pi-subagent 的 docs/07-ui.md §3.3

说明

  • 只统计顶层工具调用:带 parentToolCallId 的嵌套调用(codemode 脚本)不计入工具行,避免刷屏。pi-subagent 的子 agent 在独立的子会话里跑,它们的工具调用本来就不会出现在主会话的事件里,只体现在 agent 行。
  • 工具计数跨重启/恢复保留:session_start / session_tree 时从当前 branch 的 toolResult 重建已完成工具计数,运行中再叠加实时事件;不读 transcript 文件、不跑子进程。压缩不会清空这些计数。恢复后正在运行的工具为空,因为确实没有工具在跑。
  • 本轮数据不跨进程继承:↑Out / ↓Input / tps 只来自本次进程收到的 assistant message_end。恢复旧会话后先隐藏,直到完成一条新的响应,不会显示上一轮的遗留值。
  • 渲染不再每帧全量扫描:分支用量和 context 按 sessionId + leafId + model 缓存,只有新增 entry、切分支、换模型或压缩后才重算。
  • 没有 git 状态轮询:不显示 git status / diff,因此不存在 pi-footer #119 / #122 那类 index.lock 问题。要分支以外的 git 信息再加。
  • tps 固定占 3 列宽:低速时百位/十位留白,右侧内容不会随刷新反复伸缩;超过 999 时自然变宽。
  • context 颜色阈值:< 70% 绿、70–84% 黄、>= 85% 红。
  • 进度条和 Claude HUD 一致:填充 █、空余 ░(dim),宽度随终端 10 / 6 / 4 格自适应。
  • Cache Create / Cache Read 前分别有 Nerd Font 图标:nf-cod-edit(U+EA73)/ nf-cod-archive(U+EA98),需要 Nerd Font 终端字体。

开发

npm install
npm run check   # tsc --noEmit + vitest(agent 行渲染与点击映射是纯函数,在 src/agents.test.ts)
npm run build   # 输出到 dist/,仅用于本地渲染调试

要求 pi 1.5.2 及以上(按该版本的类型编写,已在 v1.5.2 上验证通过)。


本插件属于 Shizuku 系列 pi 插件(pi-shizuku):共用的左栏、设计语言与跨插件约定见总仓库。贡献方式见 CONTRIBUTING.md。