# Configuration reference / 配置参考

[English](#english) | [简体中文](#简体中文) | [Default JSON / 默认 JSON](#default-json)

## English

For installation and feature previews, see the [README](../README.md). This guide documents every option supported by `open-tui.json`, matching [config.ts](../extensions/open-tui/config.ts), [settings-command.ts](../extensions/open-tui/settings-command.ts), and [icons.ts](../extensions/open-tui/icons.ts).

### Storage and loading

Settings live in Pi's agent directory: `~/.pi/agent/open-tui.json` by default, or `<PI_CODING_AGENT_DIR>/open-tui.json` when `PI_CODING_AGENT_DIR` is set. If the file doesn't exist yet and the directory is writable, `pi-open-tui` creates it with the default configuration.

- **Partial overrides**: You only need to include the keys you want to change; omitted fields inherit [the defaults](#default-json).
- **Validation**: Flags must be JSON booleans (`true` / `false`), not strings like `"false"`. Invalid values for known keys fall back to their defaults. If the file is unreadable or contains invalid JSON, `pi-open-tui` falls back to defaults and shows a warning.
- **Applying edits**: Manual edits to `open-tui.json` take effect after `/reload` or in a new session.
- **Write errors**: If saving from `/open-tui` fails, your changes still apply to the current session, and a warning prompts you to check directory permissions and disk space.

### Settings dialog

Run `/open-tui` to configure the extension interactively. Options are grouped into four tabs:

| Tab | Sections |
| --- | --- |
| General | Extension, Interface, Messages & tools, Footer |
| Appearance | Icons, Editor |
| Footer | Location, Git, Runtime, Usage, Other |
| Telemetry | Enabled (standalone master switch), Measurements |

**Navigation**: `Tab` / `Shift+Tab` or `←` / `→` switches tabs; `↑` / `↓` or `Page Up` / `Page Down` moves between options; `Enter` / `Space` toggles or cycles a value; `Esc` / `q` closes the dialog. Dim section headings take up rows for readability (and count toward scroll position) but aren't selectable.

A few behaviors worth noting:

- **Compact extension tools** only appears when **Tool view** is set to **Compact**. Switching back to **Native** hides the row without resetting its saved value.
- Toggling the master **Enabled** switch installs or removes the UI once you close the dialog.
- Existing config files are forward-compatible and need no manual migration.

### General options

| Key | Default | Values and behavior |
| --- | --- | --- |
| `enabled` | `true` | Master switch for `pi-open-tui` |
| `header` | `true` | Replaces the top header; set to `false` to leave that slot to Pi or another extension |
| `inlineFooter` | `false` | Moves the two main footer rows into a compatible editor's borders (extension status rows stay separate) |
| `copyButtons` | `true` | Shows `[Copy]` buttons on code blocks, user messages, and nonempty input drafts in fullscreen mode |
| `settingsLanguage` | `"en"` | `"en"` or `"zh"` — controls the `/open-tui` dialog language |
| `cursorStyle` | `"block"` | `"block"`, `"bar"`, or `"underline"` (`"bar"` and `"underline"` require terminal cursor-shape support) |
| `icons.mode` | `"auto"` | `"auto"`, `"nerd"`, `"unicode"`, or `"ascii"` — see [Icons](#icons) |
| `thinkingPeek.lines` | `1` | `0` (off), `1`, or `2` — live reasoning preview while Pi's Hide thinking is enabled |
| `toolView.mode` | `"native"` | `"native"` or `"compact"` — applied when Pi creates each tool row |
| `toolView.extensionTools` | `false` | Extends compact mode to extension, MCP, and built-in replacement tools |
| `toolView.exclude` | `[]` | Exact tool names (including built-ins) that always keep native rendering *(JSON-only)* |

For example, the snippet below enables compact mode for all tools except `edit` and `subagent_wait`:

```json
{
  "toolView": {
    "mode": "compact",
    "extensionTools": true,
    "exclude": ["edit", "subagent_wait"]
  }
}
```

Run `/reload` or start a new session to rebuild existing transcript rows with updated tool-view settings.

### Footer options

#### Path and branch formatting

- **`footerCwdFormat`** *(JSON-only top-level key)*: Controls how the working directory is rendered. Accepts `"auto"` (default — full `~`-relative path when space permits, compacting to the directory name when narrow), `"basename"` (always the directory name), or `"full"` (absolute path without `~`, shortening path segments as needed). All three modes can truncate further in very narrow terminals.
- **Git branches**: Shown in full when space permits. As the row fills up, branch names shorten to 20 display columns first (keeping status counts intact), then shrink further if needed. Within the Git segment, status counts take priority over the branch name. Detached `HEAD` preserves its short commit hash and drops any optional tag first. These rules apply automatically to both regular and inline footers.

#### Footer segments (`footerSegments`)

All keys below are booleans inside `footerSegments`:

| Key | Default | What it controls |
| --- | --- | --- |
| `cwd` | `true` | Working directory (compacted automatically when narrow) |
| `hostname` | `false` | Short hostname (before the first dot) with a server icon |
| `sessionName` | `false` | Current session name, when set |
| `gitBranch` | `true` | Branch name, or `HEAD` plus short commit hash when detached |
| `gitStatus` | `true` | Conflicted, deleted, modified, renamed, staged, untracked, stash, and ahead/behind counts |
| `gitCommit` | `false` | Tag pointing at the detached `HEAD` commit (requires `gitBranch: true`) |
| `runtime` | `true` | Detected project runtime and version, when available |
| `context` | `true` | Context progress bar, percentage, and token count |
| `contextBar` | `true` | Visual bar and icon inside the context segment (`false` keeps percentage and tokens only) |
| `tokens` | `true` | Cumulative input/output tokens and latest assistant cache-hit percentage |
| `cost` | `true` | Cumulative session cost reported by Pi |
| `liveTps` | `true` | Live streaming speed estimate beside the working timer |
| `extensionStatuses` | `true` | Separate `ctx.ui.setStatus()` rows, including MCP status |
| `extensionSegments` | `true` | Segments injected into the main rows via the [footer event API](./footer-segments.md) |
| `capitalizeProviderName` | `true` | Capitalizes the first letter of the provider name (`false` preserves original casing) |
| `nerdIconSpacing` | `false` | Adds one extra space cell after Nerd Font icons, including runtime icons |

The provider/model label and working/done timer are always shown (`liveTps` only toggles the speed estimate beside the timer). Disabling `extensionSegments` hides contributed segments without tearing down their lifecycle—updates are still received in the background, independently of `extensionStatuses`.

### Telemetry options

All keys below are booleans inside `telemetry` and default to `true`:

| Key | What it controls |
| --- | --- |
| `enabled` | Master switch for the end-of-run telemetry summary |
| `tps` | Provider-based output tokens per second |
| `ttft` | Time to first output token |
| `duration` | Total agent run duration |
| `tokens` | Assistant input/output token counts across measured turns |
| `stalls` | Stream stalls (only displayed when a stall actually occurred) |
| `cost` | Effective rate per million reported tokens |

Live streaming speed in the footer is controlled separately by `footerSegments.liveTps`. See [usage and telemetry](./implementation.md#usage-and-telemetry) for exact formulas and caveats.

### Icons

| `icons.mode` | Behavior |
| --- | --- |
| `auto` | Uses ASCII when stdout isn't a TTY, `TERM=dumb`, or the first set locale (`LC_ALL`, `LC_CTYPE`, `LANG`) isn't UTF-8 (an unset locale passes the UTF-8 check). Otherwise uses Unicode over SSH (`SSH_TTY` or `SSH_CONNECTION`) and Nerd Font locally |
| `nerd` | Always uses Nerd Font glyphs |
| `unicode` | Portable Unicode symbols (emoji rely on your terminal's fallback font) |
| `ascii` | Plain ASCII symbols |

Because `auto` only checks the terminal environment and never inspects installed fonts, select a Nerd Font in your terminal profile if icons render as boxes—or switch to `unicode` / `ascii`. When connecting over SSH from a terminal that has a Nerd Font installed, set `icons.mode` to `"nerd"` explicitly.

If wide Nerd Font glyphs overlap the text immediately after them, enable **Footer → Other → Extra space after Nerd icons** (`footerSegments.nerdIconSpacing`). This applies to both regular and inline footers while leaving Unicode/ASCII icons and compact Git status flags untouched. Kitty users can alternatively add `narrow_symbols U+E000-U+F8FF 1` to `kitty.conf`.

## 简体中文

安装方式和功能概览见 [README](../README.zh-CN.md)。本文档列出 `open-tui.json` 支持的全部配置项，对应源码见 [config.ts](../extensions/open-tui/config.ts)、[settings-command.ts](../extensions/open-tui/settings-command.ts) 和 [icons.ts](../extensions/open-tui/icons.ts)。

### 存储与加载

配置文件位于 Pi 的 agent 目录下：默认为 `~/.pi/agent/open-tui.json`；如果设置了环境变量 `PI_CODING_AGENT_DIR`，则读取 `<PI_CODING_AGENT_DIR>/open-tui.json`。文件不存在且目录可写时，扩展会自动按默认配置生成。

- **按需覆盖**：只需填写想修改的字段，其余未写字段自动沿用[默认值](#default-json)。
- **字段校验**：布尔项必须写 JSON 布尔值（`true` / `false`），不能写成 `"false"` 这样的字符串。已知字段的非法值会回退为默认值；若文件无法读取或 JSON 格式有误，扩展会弹出警告并回退到默认配置。
- **生效时机**：手动编辑 `open-tui.json` 后，执行 `/reload` 或新开会话即可生效。
- **写入失败**：在 `/open-tui` 中修改配置时如果写入磁盘失败，新设置仍会在当前会话生效，同时界面会提示检查目录权限和磁盘空间。

### 设置窗口

运行 `/open-tui` 即可打开交互式设置面板，包含四个分页：

| 分页 | 分组 |
| --- | --- |
| 常规 | 扩展、界面、消息与工具、底栏 |
| 外观 | 图标、输入框 |
| 底栏 | 位置、Git、运行环境、用量、其他 |
| 遥测 | 启用（独立总开关）、测量指标 |

**快捷键**：`Tab` / `Shift+Tab` 或 `←` / `→` 切换分页；`↑` / `↓` 或 `Page Up` / `Page Down` 移动选项；`Enter` / `Space` 切换值；`Esc` / `q` 关闭窗口。暗色分组标题用于分隔视觉层级（会计入滚动位置），不可选中或修改。

几点交互说明：

- **紧凑显示扩展工具**仅在**工具视图**设为**紧凑**时显示；切回**原生**后会隐藏，但不会丢弃原有开关状态。
- 切换总开关**启用**后，界面的挂载或卸载会延迟到关闭设置窗口时执行。
- 旧版配置文件可直接沿用，无需手动迁移。

### 常规选项

| 配置键 | 默认值 | 可选值与说明 |
| --- | --- | --- |
| `enabled` | `true` | `pi-open-tui` 总开关 |
| `header` | `true` | 替换顶部信息栏；关闭后将位置留给 Pi 或其他扩展 |
| `inlineFooter` | `false` | 将两条主底栏嵌入兼容输入框的上下边框（扩展状态行仍独立显示） |
| `copyButtons` | `true` | 全屏模式下在代码块、用户消息和非空输入草稿上显示 `[Copy]` 按钮 |
| `settingsLanguage` | `"en"` | `"en"` 或 `"zh"`，切换 `/open-tui` 界面的语言 |
| `cursorStyle` | `"block"` | `"block"`、`"bar"` 或 `"underline"`（后两者需要终端支持光标形状控制） |
| `icons.mode` | `"auto"` | `"auto"`、`"nerd"`、`"unicode"` 或 `"ascii"`，详见[图标](#图标) |
| `thinkingPeek.lines` | `1` | `0`（关闭）、`1` 或 `2`，在 Pi 开启 Hide thinking 时实时预览推理尾行 |
| `toolView.mode` | `"native"` | `"native"` 或 `"compact"`，在 Pi 创建每条工具行时决定渲染方式 |
| `toolView.extensionTools` | `false` | 紧凑模式下同时收纳扩展、MCP 以及同名替换内置工具的扩展 |
| `toolView.exclude` | `[]` | 始终保持原生渲染的精确工具名列表，支持包含内置工具*（仅支持 JSON 配置）* |

例如，下面的配置会为所有工具启用紧凑视图，但让 `edit` 和 `subagent_wait` 保持原生卡片：

```json
{
  "toolView": {
    "mode": "compact",
    "extensionTools": true,
    "exclude": ["edit", "subagent_wait"]
  }
}
```

修改工具视图相关设置后，执行 `/reload` 或新开会话即可让已有历史记录按新规则重建。

### 底栏选项

#### 路径与分支排版

- **`footerCwdFormat`** *（仅支持 JSON 的顶层配置）*：控制工作目录的显示风格。可选 `"auto"`（默认，空间充足时显示相对主目录路径，窄屏时收拢为目录名）、`"basename"`（始终只显示目录名）或 `"full"`（不使用 `~` 的完整绝对路径，必要时缩写中间层级）。在极窄窗口下，三种模式都会按需进一步截断。
- **Git 分支名**：空间充裕时完整显示；行宽紧张时会先缩短到 20 个显示列（保留状态计数），必要时再继续缩短。Git 片段内部优先保住状态计数，其次才是分支名。分离 `HEAD` 时优先保留短哈希，先收起可选的标签。以上规则同时适用于常规底栏和内嵌底栏，无需额外开关。

#### 底栏字段（`footerSegments`）

以下配置键均位于 `footerSegments` 下，取值为布尔值：

| 配置键 | 默认值 | 说明 |
| --- | --- | --- |
| `cwd` | `true` | 当前工作目录（空间不足时自动缩短） |
| `hostname` | `false` | 短主机名（第一个点之前的部分），搭配服务器图标 |
| `sessionName` | `false` | 当前会话名称（已命名时显示） |
| `gitBranch` | `true` | 分支名；分离 `HEAD` 时显示 `HEAD` 与短提交哈希 |
| `gitStatus` | `true` | 冲突、删除、修改、重命名、已暂存、未跟踪、stash 与 ahead/behind 计数 |
| `gitCommit` | `false` | 指向分离 `HEAD` 提交的标签（需同时开启 `gitBranch`） |
| `runtime` | `true` | 识别到的项目运行环境及可用版本号 |
| `context` | `true` | 上下文进度条、百分比与 Token 用量 |
| `contextBar` | `true` | 上下文中的可视化进度条与图标；关闭后仅保留百分比和 Token 数 |
| `tokens` | `true` | 会话累计输入/输出 Token，以及最新助手回复的缓存命中率 |
| `cost` | `true` | Pi 上报的会话累计费用 |
| `liveTps` | `true` | 工作计时器旁显示的实时流式速度估算 |
| `extensionStatuses` | `true` | 独立的 `ctx.ui.setStatus()` 状态行（包含 MCP 状态） |
| `extensionSegments` | `true` | 扩展通过[底栏事件接口](./footer-segments.md)注入主底栏的片段 |
| `capitalizeProviderName` | `true` | 将服务商名称首字母大写；关闭则保留原始大小写 |
| `nerdIconSpacing` | `false` | 在 Nerd Font 图标后额外留一格空隙（含运行环境图标） |

服务商/模型名称以及工作/完成计时器不设隐藏开关，`liveTps` 仅控制计时器旁的实时速度。关闭 `extensionSegments` 只会隐藏外部片段，不会中断其数据更新和生命周期，且与 `extensionStatuses` 互不影响。

### 遥测选项

以下配置键均位于 `telemetry` 下，默认全部为 `true`：

| 配置键 | 说明 |
| --- | --- |
| `enabled` | 任务结束遥测汇总的总开关 |
| `tps` | 基于服务商用量的每秒输出 Token |
| `ttft` | 首字输出延迟 |
| `duration` | Agent 完整运行耗时 |
| `tokens` | 本次运行各统计轮次的助手输入/输出 Token |
| `stalls` | 流式输出停顿（仅实际检测到停顿时才显示） |
| `cost` | 每百万上报 Token 的综合美元费率 |

底栏中的实时流式速度由 `footerSegments.liveTps` 单独控制。各指标的计算方式与边界条件见[用量与遥测](./implementation.md#用量与遥测)。

### 图标

| `icons.mode` | 选择规则 |
| --- | --- |
| `auto` | 若 stdout 不是 TTY、`TERM=dumb`，或首个已配置的 locale（依次检查 `LC_ALL`、`LC_CTYPE`、`LANG`）不是 UTF-8，则使用 ASCII（未设置 locale 时默认通过 UTF-8 检查）。否则，检测到 SSH（`SSH_TTY` 或 `SSH_CONNECTION`）时使用 Unicode，本地终端默认使用 Nerd Font |
| `nerd` | 始终使用 Nerd Font 图标 |
| `unicode` | 通用 Unicode 符号（emoji 依赖终端自身的回退字体） |
| `ascii` | 纯 ASCII 字符 |

`auto` 模式只检查终端环境，不会探测本机是否安装了字体。如果图标显示成方框，请在终端配置里选中 Nerd Font，或直接改用 `unicode` / `ascii`。通过 SSH 连接且本地客户端已配置 Nerd Font 时，可以手动设为 `nerd`。

如果部分较宽的 Nerd Font 图标紧贴甚至压住后面的文字，可以开启 **底栏 → 其他 → Nerd 图标后额外留空**（`footerSegments.nerdIconSpacing`）。该项同时作用于常规和内嵌底栏，不影响 Unicode/ASCII 图标和紧凑 Git 标记。Kitty 用户也可以直接在 `kitty.conf` 中添加 `narrow_symbols U+E000-U+F8FF 1`。

## Default JSON

The complete default configuration is shared by both language references. Set `settingsLanguage` to `"zh"` for the Chinese settings interface.

以下为中英文共用的完整默认配置。将 `settingsLanguage` 设为 `"zh"` 即可将设置面板切换为简体中文。

```json
{
  "enabled": true,
  "header": true,
  "inlineFooter": false,
  "copyButtons": true,
  "settingsLanguage": "en",
  "cursorStyle": "block",
  "icons": {
    "mode": "auto"
  },
  "footerCwdFormat": "auto",
  "footerSegments": {
    "cwd": true,
    "hostname": false,
    "sessionName": false,
    "gitBranch": true,
    "gitStatus": true,
    "gitCommit": false,
    "runtime": true,
    "context": true,
    "contextBar": true,
    "tokens": true,
    "cost": true,
    "liveTps": true,
    "extensionSegments": true,
    "extensionStatuses": true,
    "capitalizeProviderName": true,
    "nerdIconSpacing": false
  },
  "telemetry": {
    "enabled": true,
    "tps": true,
    "ttft": true,
    "duration": true,
    "tokens": true,
    "stalls": true,
    "cost": true
  },
  "thinkingPeek": {
    "lines": 1
  },
  "toolView": {
    "mode": "native",
    "extensionTools": false,
    "exclude": []
  }
}
```
