pi-file-viewer

Terminal file viewer for Pi: a syntax-highlighted sidebar reader with tabs, search, links, selection and live reload.

Packages

Package details

extension

Install pi-file-viewer from npm and Pi will load the resources declared by the package manifest.

$ pi install npm:pi-file-viewer
Package
pi-file-viewer
Version
0.4.0
Published
Dec 1, 2026
Downloads
470/mo · 470/wk
Author
elyor-sh
License
MIT
Types
extension
Size
170.7 KB
Dependencies
0 dependencies · 2 peers
Pi manifest JSON
{
  "extensions": [
    "./index.ts"
  ]
}

Security note

Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.

README

pi-file-viewer

CI License: MIT

A terminal file viewer for Pi: a syntax-highlighted reader that opens as a right-hand sidebar panel, with tabs, search, link following, range selection and live reloads. It brings the Codex CLI sidebar reader experience to Pi extensions.

pi-file-viewer: a right-hand sidebar file viewer next to the chat

Status: early (0.4.x). The UI and keybindings may still change between minor releases.

Requirements

Pi 1.7.0 or newer (the extension uses the exported highlightCode() and copyToClipboard() helpers). No runtime dependencies.

Install

# from npm (recommended)
pi install npm:pi-file-viewer

# from GitHub, pinned to a release
pi install git:github.com/elyor-sh/pi-file-viewer@v0.4.0

# from a local checkout
pi install ./pi-file-viewer

# for a single run, without installing
pi -e ./pi-file-viewer/index.ts

Usage

/view                    folder-tree & fuzzy picker in the right sidebar
/view src/app.ts         open a file
/view src/app.ts:42      open at a line
/view src/app.ts#L42     same thing
/view src/               picker rooted at a directory
/view --wt <branch>      open rooted at a matching git worktree
/view --full [path]      open in fullscreen instead of the sidebar

ctrl+shift+o opens the picker without typing the command (terminals that cannot distinguish it from ctrl+o should use /view).

Layout

The reader opens as a full-height panel anchored to the right edge, like the Codex sidebar: the conversation stays visible on the left, the file is on the right, and a divider marks the boundary.

  • z toggles between sidebar and fullscreen; the scroll position is preserved.
  • /view --full starts in fullscreen, PI_FILE_VIEWER_LAYOUT=fullscreen makes it the default.
  • PI_FILE_VIEWER_WIDTH sets the panel width, for example 60% or 90 columns. The default is 55% of the terminal, never narrower than 40 columns.
  • Terminals narrower than 80 columns fall back to fullscreen automatically.

Pi does not expose a split-pane layout API to extensions, so the sidebar is a right-anchored overlay. While it is open it owns the keyboard, and the conversation behind it is covered rather than reflowed to the remaining width. z or q returns to the chat.

What it does

  • Syntax highlighting matched to the active Pi theme (highlightCode).
  • Line numbers, word wrap (toggle with w), horizontal scrolling when wrap is off.
  • Search with live match painting, current-match highlight, and n / N navigation.
  • Tabs for every opened file, x closes one, [ / ] cycles, clicking a tab activates it and clicking its x closes it.
  • Follow paths under the cursor with Tab: relative and absolute paths, @/ aliases, extension probing (.ts, .tsx, .js, ...), index.* directories, :line:col and #Lline.
  • Git change gutter: files with uncommitted changes show a green bar on added lines, a yellow bar on modified lines and a red tick where lines were deleted (all vs HEAD), plus +added ~modified −deleted counts in the status rule. Changed lines are tinted (d toggles it), c / C jump between changes. The diff runs in the background with git diff -U0 and never delays opening a file.
  • Cursor & selection: arrows move a cursor (also in short files), v / V / shift+arrows / mouse drag select, y copies through Pi's clipboard integration.
  • Send code to the chat: a appends src/main.tsx#L42-L65 (selection or current line) to Pi's chat input, A does the same and closes the viewer.
  • Live reload via directory watching (atomic saves included); the footer reports edits.
  • Folder-tree & fuzzy picker using git ls-files and current git status:
    • Marks working-tree and staged changes on files (M modified, A staged new, ? untracked, R renamed, U conflicted) and flags parent folders containing changes with ●.
    • Filter toggle between Changed (only modified/new files, auto-expanded) and All (full project tree, folders collapsed by default). Opens in Changed when there are uncommitted changes, or All when the repo is clean or outside git.
    • Typing switches to flat fuzzy search across the active filter; clearing the query returns to the folder tree.
    • Falls back to a bounded directory walk when the project is not a git repository.
  • Git worktree switcher (ctrl+w or shift+tab in the picker, W or ctrl+w in the reader, or /view --wt <name>):
    • Lists all active worktrees with branch/detached labels, relative paths, and uncommitted change counts.
    • Switching worktrees reloads the picker in that worktree while keeping open tabs from other worktrees intact and disambiguated by worktree label.
  • Mouse support in fullscreen mode: wheel scrolls, clicks select a tab or place the cursor, dragging selects (shift+click extends).

Keys

Key Action
up/down, k/j scroll one line
PgUp/PgDn, b/space page up / down
ctrl+u / ctrl+d half a page up / down
g / G (Home/End) jump to top / bottom
0 / $ line start / end
/, f3, ctrl+f search
n / N next / previous match (also in the search prompt)
Tab open the path under the cursor
v / V select characters / whole lines (or shift+arrows, or drag with the mouse in fullscreen)
y copy the selection, or the current line
a add a path#L42-L65 reference for the selection (or current line) to the chat input
A same, then close the viewer to keep typing
w toggle word wrap
z toggle sidebar / fullscreen
[ / ] previous / next tab
x close tab (closing the last one returns to the file list)
c / C next / previous git change
d toggle changed-line highlight
r reload from disk
o file picker
W, ctrl+w switch git worktree
? help
esc back to the file list with the current file selected (enter reopens it, esc again closes the viewer)
q, ctrl+c close the viewer

Select mode: arrows / hjkl (or shift+arrows) extend the selection, PgUp/PgDn page, 0/$ go to line start/end, w/b move by word, V / v switch between line and character selection, y copies, a / A add a reference to the chat, esc cancels.

Search prompt: type to filter, enter / shift+enter next/previous match, up/down move between matches, ctrl+u clears, esc closes the prompt (matches stay highlighted).

Picker: navigate the folder tree with up/down (or ctrl+p/ctrl+n), left/right to collapse/expand folders, Tab (or ctrl+g) to toggle Changed / All files, ctrl+w (or shift+tab) to open the git worktree switcher, PgUp/PgDn to jump, enter to toggle a folder or open a file, esc to close the viewer. Type to switch to flat fuzzy filtering; clear the query to return to the tree.

Configuration

Variable Default Meaning
PI_FILE_VIEWER_LAYOUT sidebar sidebar or fullscreen.
PI_FILE_VIEWER_WIDTH 55% Panel width (60% or 90 columns); sidebar only.
PI_FILE_VIEWER_MAX_BYTES 2097152 (2 MB) Maximum bytes read from a file; larger files open truncated.
PI_FILE_VIEWER_MAX_LINES 20000 Maximum displayed lines.

Files containing NUL bytes are reported as binary and are not opened. Lines wider than 100,000 terminal cells are not wrapped, so a single minified line cannot stall rendering.

Design notes

  • index.ts registers /view and the shortcut, resolves the command argument, and runs the overlay loop that reopens the component when z switches layouts.
  • src/layout-mode.ts holds the layout policy (sidebar width, narrow-terminal fallback, --full parsing) as pure functions.
  • src/layout.ts owns the display-column coordinate system. Lines are tab-expanded once; wrapping produces Segments and a prefix index so any visual row maps to a source line in O(log n). Highlighted ANSI text is sliced with sliceByColumn, so plain and styled text always share columns.
  • src/search.ts reports matches in display columns, src/links.ts detects and resolves paths, src/files.ts lists project files with current git status, src/worktrees.ts discovers git worktrees and their change counts, src/tree.ts builds and flattens the collapsible folder tree, src/document.ts loads and normalizes files.
  • src/viewer.ts is the component: state, input handling, painting and the tab strip. It caches rendered lines per (width, height, version) and re-highlights lazily after theme changes. Only the visible rows are painted.

Limitations

  • The sidebar covers the conversation behind it; Pi does not let extensions reflow the transcript into the remaining columns.
  • No image previews and no side-by-side diff view (both exist in the Codex reader).
  • Markdown is displayed as line-numbered source, not rendered prose.
  • URLs are reported in the status line rather than opened in a browser.
  • Selection is keyboard driven; drag-selection is not implemented.

Contributing

See CONTRIBUTING.md. Run npm run typecheck and npm test before sending a pull request; both run in CI on Node 24 and 26.

License

MIT.