pi-file-viewer
Terminal file viewer for Pi: a syntax-highlighted sidebar reader with tabs, search, links, selection and live reload.
Package details
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
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.

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.
ztoggles between sidebar and fullscreen; the scroll position is preserved./view --fullstarts in fullscreen,PI_FILE_VIEWER_LAYOUT=fullscreenmakes it the default.PI_FILE_VIEWER_WIDTHsets the panel width, for example60%or90columns. 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/Nnavigation. - Tabs for every opened file,
xcloses one,[/]cycles, clicking a tab activates it and clicking itsxcloses it. - Follow paths under the cursor with
Tab: relative and absolute paths,@/aliases, extension probing (.ts,.tsx,.js, ...),index.*directories,:line:coland#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 −deletedcounts in the status rule. Changed lines are tinted (dtoggles it),c/Cjump between changes. The diff runs in the background withgit diff -U0and never delays opening a file. - Cursor & selection: arrows move a cursor (also in short files),
v/V/shift+arrows / mouse drag select,ycopies through Pi's clipboard integration. - Send code to the chat:
aappendssrc/main.tsx#L42-L65(selection or current line) to Pi's chat input,Adoes 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-filesand currentgit status:- Marks working-tree and staged changes on files (
Mmodified,Astaged new,?untracked,Rrenamed,Uconflicted) and flags parent folders containing changes with●. - Filter toggle between
Changed(only modified/new files, auto-expanded) andAll(full project tree, folders collapsed by default). Opens inChangedwhen there are uncommitted changes, orAllwhen 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.
- Marks working-tree and staged changes on files (
- Git worktree switcher (
ctrl+worshift+tabin the picker,Worctrl+win 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.tsregisters/viewand the shortcut, resolves the command argument, and runs the overlay loop that reopens the component whenzswitches layouts.src/layout-mode.tsholds the layout policy (sidebar width, narrow-terminal fallback,--fullparsing) as pure functions.src/layout.tsowns the display-column coordinate system. Lines are tab-expanded once; wrapping producesSegments and a prefix index so any visual row maps to a source line in O(log n). Highlighted ANSI text is sliced withsliceByColumn, so plain and styled text always share columns.src/search.tsreports matches in display columns,src/links.tsdetects and resolves paths,src/files.tslists project files with current git status,src/worktrees.tsdiscovers git worktrees and their change counts,src/tree.tsbuilds and flattens the collapsible folder tree,src/document.tsloads and normalizes files.src/viewer.tsis 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.