@egorlem/pi.zsh0.4.0
A native zsh tool for the Pi agent: no bash wrapper, no double parsing, and no user startup files in the run.
Untested on omp
This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.
Reports 0
No reports yet.
Readme
pi.zsh — a native zsh tool for the Pi agent
One tool, one process: zsh runs directly, with no bash wrapper.
Why it exists
Running zsh through bash looks like this:
bash -c 'zsh -c "..."'
That has three problems:
- Double parsing. Bash eats one layer of
$,\, quotes, and tabs, so zsh sees a string that has already changed. - An extra process. The tree becomes
pi → bash → zsh → command, which changes$PPID, the process group, and signal handling. - Startup leakage. zsh still reads your
.zshenv— and.zshrcwhen the shell is interactive — plus everything they load, so command behaviour can depend on config.
pi.zsh runs zsh directly:
pi → zsh → command
Your .zshrc is read the way your own shell reads it, and the host environment is inherited the way bash inherits it. If you want a clean shell instead, set zshStartup to isolated.
Install
Requires zsh 5.0.8 or newer: macOS ships it, on Linux it has to be installed. Older versions are not supported — the extension relies on zsh 5.x behaviour. Nothing else is needed: the extension uses only Node builtins and typebox, which Pi provides.
From npm
pi install npm:@egorlem/pi.zsh
The command adds the package to packages in ~/.pi/agent/settings.json and installs it. Pi finds the extension through the pi.extensions manifest in package.json and registers the zsh tool — there is nothing else to enable: extension tools are active by default.
Project-local, in .pi/settings.json (Pi reads that file only after project trust):
pi install npm:@egorlem/pi.zsh -l
Managing the install:
pi list # what is installed
pi update --extensions # update packages
pi remove npm:@egorlem/pi.zsh
A version in the spec is pinned: npm:@egorlem/pi.zsh@0.1.0 will not be moved by pi update --extensions. Without a version, Pi installs the current release and keeps it updated.
From git
Clone the repository anywhere and install the path to the clone:
git clone https://github.com/egorlem/pi.zsh.git
pi install "$PWD/pi.zsh"
Pi records the path relative to the settings directory (~/.pi/agent/settings.json for personal settings, .pi/ for a project) and loads the clone in place: no copy, no dependency install, so edits are visible immediately — /reload or a new session is enough. If you move the clone, the recorded path breaks: run pi remove and pi install again.
Updating is git pull in the clone; pi update --extensions only handles npm and git sources and leaves local paths alone.
Without installing, for one run
pi -e npm:@egorlem/pi.zsh
pi -e "$PWD/pi.zsh" # the package from a clone
pi -e "$PWD/pi.zsh/index.ts" # a single file, no manifest
The npm package is cached in ~/.pi/agent/tmp/extensions/; a local path is read in place. Nothing is written to settings, so the extension exists only for that run — handy for trying it before it lands in the config.
Enabling inside Pi
Once installed, the zsh tool is available in a new session (and after /reload in an open one) next to the built-in read, bash, edit, and write.
If the tool is not wanted in a session, or was turned off:
pi --tools zsh # allow only zsh
pi --tools +zsh # add zsh to the selected tools
pi --exclude-tools zsh # remove zsh
Permanently, through settings.json:
{
"defaultTools": ["+zsh"]
}
+name/-name entries change the inherited set instead of replacing it, so +zsh does not disable the other tools. pi config opens the same control in the TUI: Tab switches scope (personal or project), and package resources and built-in extensions can be toggled there.
--no-extensions disables the extension entirely, together with its permission gate.
Extension settings
Both settings are read from settings.json, personal or project:
{
"zshPath": "/usr/bin/zsh",
"zshStartup": "isolated",
"zshPermissionGate": true
}
Only zshPath has no default; the other two start as interactive and off.
zshPath— an explicit path to zsh; if it is set but does not point at an executable zsh, the tool returns a[zshPath]error instead of a silent fallback;zshStartup—interactive(default) orisolated; see "Environment" below;zshPermissionGate— off by default;trueasks for confirmation on dangerous commands.
See "Path to zsh" and "Permission" below.
The /zsh command
/zsh opens the tool's settings — permission gate and startup mode — in the
same list widget Pi's own /settings uses: Enter or Space switches, Escape
closes. Without a UI: /zsh show, /zsh on, /zsh off.
It writes <agent-dir>/settings.json, never project settings. A running session
keeps settings in memory, so /reload applies the change.
Usage
zsh is not a command you type; it is a tool the model calls. After installing, it appears in the session's tool list and the model picks it when a task needs zsh specifically. You describe the task in words; the JSON below is the call's arguments, worth knowing so you can tell what the model passes and phrase tasks more precisely.
For example, a request and the call behind it:
show the zsh version and the current directory
{
"script": "print -r -- $ZSH_VERSION; print -r -- $PWD"
}
Every call is a fresh zsh process. Nothing carries over between calls: variables, cd, functions, and zmodload from a previous call are not visible, so related commands belong in one script.
script or file
A call has exactly one of the two fields. script is code in argv, with no temporary files; file is a path to an existing regular file.
{ "script": "print -r -- $ZSH_VERSION" }
{ "file": "/abs/path/to/init.zsh" }
The file path can be absolute or relative to cwd; ~ is not expanded — resolve() treats it literally, so write the full path. In file mode $0 is the file path, in script mode it is zsh.
args and cwd
{
"script": "print -r -- \"$1 in $PWD\"",
"args": ["value"],
"cwd": "/tmp"
}
args become $1, $2, ...; cwd is the working directory instead of the session directory. Normally the model fills both in as the task requires.
Calling the tool by hand
To call the tool without an interactive session, from the directory that holds the clone:
pi -p --no-session -e ./pi.zsh --tools zsh \
'Use the zsh tool with script exactly: print -r -- ok'
Parameters
| Parameter | Meaning |
|---|---|
script |
zsh code; mutually exclusive with file |
file |
path to a .zsh file; mutually exclusive with script |
args |
positional arguments, $1... |
cwd |
working directory; defaults to ctx.cwd |
timeoutMs |
timeout, 30 000 ms by default |
profile |
plain (default) or tty |
env |
explicit additions or overrides on top of the inherited environment |
home |
override HOME |
zdotdir |
override ZDOTDIR |
path |
override PATH |
Profiles
plain:TERM=dumb,NO_COLOR=1,LC_ALL=C,COLUMNS=200— for scripts and parsing.tty:TERM=xterm-256color,COLORTERM=truecolor,COLUMNS=80, noNO_COLOR— for themes and prompt code.
Environment
zshStartup chooses how much of your shell the tool reproduces:
interactive (default) |
isolated |
|
|---|---|---|
ZDOTDIR |
yours, or HOME when unset |
temporary, removed after the call |
| startup files | /etc/zshenv, your .zshenv and .zshrc |
only /etc/zshenv |
host FPATH |
kept | removed |
| shell flags | -i -c |
-c |
interactive is the default, the same full-access stance Pi itself takes: the
shell behaves like yours, so fpath, completions, aliases, and functions from
.zshrc are all there. The price is that your rc code runs — calls are slower
(100–350 ms), can print extra output, and depend on your config.
isolated is for reproducibility: no plugins, no aliases, no prompt, no user
fpath. The timeout still applies in both modes.
Both modes share the rest:
- the host environment is inherited the way bash inherits it;
HOMEstays the real home directory;TMPDIRis temporary and removed after the call;HISTFILE=/dev/null;SHELLis set to the zsh path.
In isolated mode a script that needs a non-standard fpath has to set it explicitly:
fpath=(/path/to/functions $fpath)
Path to zsh
By default the extension looks for zsh in $SHELL, /usr/bin/zsh, /bin/zsh, /usr/local/bin/zsh, Homebrew and Linuxbrew, and ~/.local/bin.
It can be set explicitly in settings.json:
{
"zshPath": "/usr/bin/zsh"
}
If zshPath is set but does not point at an executable zsh, the tool returns a [zshPath] error instead of a silent fallback.
Permission
The tool is annotated as:
readOnlyHint: false
destructiveHint: true
openWorldHint: true
The built-in permission gate checks script, file, and args for dangerous constructs:
rmwith-r/-f;sudo/doas;mkfs;dd ... of=;chmod/chown ... 777;shutdown/reboot/poweroff/halt;systemctl start|stop|restart|...;- writes to
/dev/sd*.
The gate is off by default — Pi's own stance is full access, so nothing is blocked or asked unless you opt in. Turn it on with:
{
"zshPermissionGate": true
}
When it is on, the TUI asks for confirmation and shows the source (script,
args, or the file path), the line number, two lines of context around the
match, and the pattern that fired. In non-UI modes it blocks the call.
The gate is a text heuristic, not a parser: it looks for patterns in script, args, and the contents of file (the first 128 KiB) and cannot see what is assembled at runtime. eval, string concatenation, a variable holding a command, or a call to an external script all pass it by. This is not a sandbox: permissions, the file system, and the network remain Pi's.
Result
The model receives text: a status line and output sections. The TUI shows the same — the call arguments, the status, stdout/stderr:

The status line is built from exit N, killed, truncated, and the duration. The second call shows that a non-zero exit code is not a tool error: the result comes back as usual, stdout and stderr are separated, and isError follows the exit code.
Besides text the tool returns details — the call is rendered from them, and they are the practical way to check a result programmatically:
| Field | Meaning |
|---|---|
exitCode |
exit code; 128 when the process was killed by a signal |
stdout, stderr |
captured output, up to 128 KiB each |
killed |
true when a timeout or cancellation fired |
truncated |
true when output exceeded the limit |
durationMs |
how long the call took |
signal |
the terminating signal, or null |
cwd |
the directory the script ran in |
profile |
plain or tty |
startup |
isolated or interactive |
zshPath |
which zsh ran |
Output is capped at 128 KiB per stream: the beginning and the end are kept, the middle is replaced with … [truncated N bytes] ….
Diagnostics
Errors carry a bracketed label that shows which input did not fit. cwd, file, home, and zdotdir resolve from the session directory; ~ is not expanded.
| Label | When it appears | What to do |
|---|---|---|
[input] |
both script and file were passed, or neither |
keep exactly one field |
[cwd] |
the directory is missing or is not a directory | check the path |
[file] |
the file is missing or is not a regular file | use a full path or a path from cwd |
[home], [zdotdir] |
the overridden directory does not exist | check the path or drop the parameter |
[env] |
the environment could not be built: temporary directories, HOME, PATH |
read the text after the label |
[zsh] |
zsh was not found or failed to start | set zshPath |
[zshPath] |
the explicit path is not a string or not an executable zsh | fix or remove the setting |
Worth knowing beyond errors:
- timeout —
killed: true, the process getsSIGTERM, and after 5 secondsSIGKILLto the whole process group;exitCodeis128when no exit code arrived; - truncation —
truncated: true,stdout/stderrhold only the beginning and the end, the middle is replaced with a marker; - stdin is closed —
readandcatcannot hang the call, they get EOF immediately.
Limitations
- Needs zsh 5.0.8 or newer; 4.x and earlier are neither tested nor supported. The version is not checked at runtime — an old zsh is not rejected, it may simply behave differently.
- Non-interactive zsh only. PTY, ZLE, and interactive completion tests are not part of the active version.
- No custom rendering.
- No full output on truncation.
- The permission gate is a pattern heuristic, not a sandbox.
Maintained by Egor Lem. Licensed under WTFPL Ver. III (see LICENSE for details).