Built-in tools
PiSharp has Pi v1.5.0’s built-in tools with the same names, parameters, limits and messages. A session starts with read, bash, edit and write. grep, find and ls are registered but off until you select them. tool_search and codemode come from built-in extensions.
This page describes the tools under the default pi tool policy, where they take any path, as in Pi. Relative paths resolve against the working folder, and a leading ~ against your home folder.
Limits shared by the tools
Section titled “Limits shared by the tools”Tool output that goes to the model is cut at 2000 lines or 50 KB (51,200 bytes), whichever comes first. Each tool says what it cut and how to see more.
| Tool | Keeps | Notice |
|---|---|---|
read |
The first lines from offset. |
[Showing lines X-Y of N. Use offset=Z to continue.] |
bash |
The last lines. | [Showing lines X-Y of N. Full output: <file>] |
grep, find, ls |
The first results. | A limit notice, such as 100 matches limit reached. Use limit=200 for more, or refine pattern |
Reads a text file or an image.
| Parameter | Type | Required | Meaning |
|---|---|---|---|
path |
string | yes | File to read. |
offset |
number | no | First line to read, counting from 1. |
limit |
number | no | Most lines to read. |
- Text past the line or byte limit ends with a notice:
[Showing lines 1-2000 of 5000 (50.0KB limit). Use offset=2001 to continue.], or[3000 more lines in file. Use offset=2001 to continue.]whenlimitstopped it. - A first line longer than 50 KB returns a hint to read it with
sed -n '<line>p' <file> | head -c 51200instead. - An
offsetpast the end is an error:Offset 120 is beyond end of file (100 lines total). - The CLI reads files of up to 64 MiB. A larger file fails with
File content exceeds the supported input limit.
Images
Section titled “Images”read recognizes PNG, JPEG, GIF, WebP and BMP files by their content, not their extension. PiSharp decodes them with SkiaSharp, where Pi uses Photon, and follows Pi’s steps:
- It applies the EXIF orientation.
- An image within 2000x2000 whose base64 data is under 4.5 MB goes to the model unchanged.
- Otherwise, with
images.autoResizeon (the default), it fits the image in 2000x2000 and tries the smaller of PNG and JPEG at quality 80, then the other, then JPEG at 85, 70, 55 and 40, and keeps the first result under 4.5 MB. - If none fits, it shrinks the image by a quarter and tries again.
The result carries the image and a note about any resize. An image that can’t fit is left out with [Image omitted: could not be resized below the inline image size limit.]. If the model doesn’t take images, PiSharp 1.5.2 and earlier add the note [Current model does not support images. The image will be omitted from this request.] to the result. images.blockImages keeps every image away from the provider. See Settings.
From PiSharp 1.6.0, as in Pi 1.6.0, read stores no such note, because it stayed in the session and was replayed to the model after a switch to a vision model. The image is still replaced with a placeholder for each request to a model without image input. The result names the model in details.imageUnsupportedByModel, and the terminal UI shows [<model> does not support images; it saw a placeholder instead] from that detail, also when the result is collapsed. A read that is cancelled while the file is being opened returns a cancelled result with Operation aborted.
Creates or replaces a file, and creates missing parent folders.
| Parameter | Type | Required | Meaning |
|---|---|---|---|
path |
string | yes | File to write. |
content |
string | yes | The whole new content. |
Pi has no size limit. In the CLI, one write call’s arguments can hold up to 8 MiB (8,388,608 characters) of JSON, so one call writes a little under 8 MiB of plain text. Characters that JSON escapes, such as <, & or accented letters, count up to six characters each. Write a larger file in parts, for example with bash.
Replaces exact text in one file.
| Parameter | Type | Required | Meaning |
|---|---|---|---|
path |
string | yes | File to edit. |
edits |
array of { oldText, newText } |
yes | One or more replacements. |
Pi’s older forms also work: a single top-level oldText and newText, and edits sent as a JSON string.
Matching follows Pi:
- Every
oldTextis matched against the original file, not against the result of earlier edits. - Exact matching comes first. If that fails, PiSharp matches again with both sides normalized: Unicode NFKC, trailing whitespace removed from each line, curly quotes made straight, Unicode dashes made
-and special spaces made plain spaces. Lines outside the edited regions keep their original text. - Each
oldTextmust match exactly once, and edits must not overlap. - Line endings are kept: a CRLF file stays CRLF. A byte order mark is kept too.
The errors are Pi’s:
| Error | Cause |
|---|---|
Could not find the exact text in <path>. The old text must match exactly including all whitespace and newlines. |
No match, even normalized. |
Found N occurrences of the text in <path>. The text must be unique. Please provide more context to make it unique. |
More than one match. |
edits[i] and edits[j] overlap in <path>. Merge them into one edit or target disjoint regions. |
Two edits touch the same text. |
oldText must not be empty in <path>. |
An empty oldText. |
No changes made to <path>. The replacement produced identical content. ... |
The edit changes nothing. |
With several edits, the messages name the edit, such as Could not find edits[2] in <path>. The CLI edits files of up to 64 MiB, and the diff shown in the terminal UI is cut at 4096 characters.
Runs a shell command in the working folder.
| Parameter | Type | Required | Meaning |
|---|---|---|---|
command |
string | yes | The command. |
timeout |
number | no | Seconds before the command is stopped. No default: a command runs until it ends. |
PiSharp picks the shell as Pi does:
| Platform | Order |
|---|---|
| Windows | The shellPath setting, then Git Bash under Program Files or Program Files (x86), then bash.exe on PATH. |
| Linux, macOS | The shellPath setting, then /bin/bash, then bash on PATH, then sh. |
The command runs with -c. The old WSL bash.exe gets it on stdin with -s instead. shellCommandPrefix is put on its own line before the command. The command inherits your environment, with <agentDir>/bin first on PATH and the session variables PI_SESSION_ID, PI_SESSION_FILE, PI_PROVIDER, PI_MODEL and PI_REASONING_LEVEL set.
Output
Section titled “Output”- The model sees the last 2000 lines or 50 KB of combined stdout and stderr. When output is cut, the full output is saved to
pi-bash-<id>.login the system temp folder and the notice names it. - From PiSharp 1.6.0, output that ends in one line longer than the kept tail shows the end of that line (PiSharp 1.5.2 returned no output for it, with a notice like
[Showing lines 3-2 of 2]). - A non-zero exit code makes the result an error that ends with
Command exited with code N. - A timeout ends with
Command timed out after N seconds, and an abort withCommand aborted. - The structured result, which code mode scripts get, is
{ output, truncated, full_output_path?, exit_code, wall_time_seconds }.
Searches file contents with ripgrep (rg). Off by default.
| Parameter | Type | Required | Meaning |
|---|---|---|---|
pattern |
string | yes | A regular expression, or a literal string with literal. |
path |
string | no | Folder or file to search. Default: the working folder. |
glob |
string | no | File filter relative to path, such as src/**/*.ts. Without a /, such as *.ts, it matches file names at any depth. |
ignoreCase |
boolean | no | Case-insensitive search. Default false. |
literal |
boolean | no | Treat pattern as plain text. Default false. |
context |
number | no | Lines to show before and after each match. Default 0. |
limit |
number | no | Most matches. Default 100. |
PiSharp runs rg --no-config --json --line-number --color=never --hidden, adding --ignore-case, --fixed-strings and --glob as asked, so a RIPGREP_CONFIG_PATH file can’t change how the tool searches. It respects .gitignore. Lines longer than 500 characters are cut, with a notice to use read for the full line.
Finds files by glob pattern with fd. Off by default.
| Parameter | Type | Required | Meaning |
|---|---|---|---|
pattern |
string | yes | Glob, such as *.ts, **/*.json or src/**/*.spec.ts. Without a / it matches file names at any depth. |
path |
string | no | Folder to search. Default: the working folder. |
limit |
number | no | Most results. Default 1000. |
PiSharp runs fd --glob --color=never --hidden --max-results <limit>. Outside a git repository it adds --no-require-git, so .gitignore files still apply. Paths in the result are relative to the search folder.
How a pattern with a / is matched differs by version:
| Version | A pattern with a / |
|---|---|
| PiSharp 1.5.2 and earlier | Matches the whole path (--full-path), with **/ added in front when needed. src/*.ts also finds pkg/src/a.ts, and a pattern can match through folders above the search folder. |
| PiSharp 1.6.0 and later, as Pi 1.6.0 | Is relative to the search folder, like grep’s glob. src/*.ts finds src/a.ts and not pkg/src/a.ts; use **/src/*.ts to match at any depth. A leading ./ is accepted. No folder above the search folder can match. |
From PiSharp 1.6.0, PiSharp gives fd the pattern behind the escaped search folder on Linux and macOS, and adds --ignore-case when the pattern is all lower case. On Windows fd lists the entries and PiSharp matches the relative path itself, because fd does not match --full-path globs there. The Linux and macOS arguments were checked as values; no fd run on those systems is recorded locally.
Lists a folder.
| Parameter | Type | Required | Meaning |
|---|---|---|---|
path |
string | no | Folder to list. Default: the working folder. |
limit |
number | no | Most entries. Default 500. |
Entries are sorted, folders end with /, and dot files are included.
ripgrep and fd
Section titled “ripgrep and fd”grep and find use rg and fd from <agentDir>/bin or your PATH. If one is missing, PiSharp downloads it from its GitHub releases into <agentDir>/bin the first time it’s needed, as Pi does. PI_OFFLINE=1 or --offline stops the download. Downloads exist only for x64 and arm64; on other architectures, such as 32-bit ARM, PiSharp warns and you install rg and fd with your package manager.
tool_search
Section titled “tool_search”Finds tools the model can’t see yet and turns them on. It comes from the builtin:tool-search extension.
| Parameter | Type | Required | Meaning |
|---|---|---|---|
query |
string | yes | What to look for. Must not be empty. |
limit |
number | no | Most tools to load. A positive integer, default 8. |
It ranks registered tools that are hidden from the model, such as MCP tools with deferred or codemode exposure, with BM25, and activates the matches for the next model call. A tool whose name is the query comes first, then tools matching more of the query’s words; a word in the tool name counts for more than any number of mentions in its description. Words in any script match, and text written without spaces, such as Chinese or Thai, is split with the system’s ICU word rules, as Pi does with Intl.Segmenter. It is registered off. It turns on when an MCP server has deferred tools, or when you select it with --tools or defaultTools. See MCP.
codemode
Section titled “codemode”Runs JavaScript that calls the other tools. It comes from the builtin:codemode extension and is registered off.
| Parameter | Type | Required | Meaning |
|---|---|---|---|
code |
string | yes | Raw JavaScript, optionally starting with a // @options: line. |
Turn it on with --tools +codemode or "defaultTools": ["+codemode"]. MCP servers with codemode exposure turn it on unless autoEnableCodemode is false in mcp.json. See Code mode for the language, globals and limits.
powershell
Section titled “powershell”There is no powershell tool in the PiSharp CLI. Pi v1.5.0 has one for Windows; PiSharp hasn’t ported it to the CLI yet, and the Parity page lists it as deferred. The name is reserved, and the terminal UI can show a powershell call from an extension. On Windows, bash runs through Git Bash.
Tool corrections in 1.5.0.1
Section titled “Tool corrections in 1.5.0.1”PiSharp 1.5.0.1 preserves mixed line endings during edits, bounds large-file read/search output, corrects relative search globs and argument expansion, preserves Unicode truncation boundaries, and avoids repeated whole-history copying of streamed tool arguments. Process capture is bounded while cleanup retains ownership of the complete child tree. See the source/test mapping for the corresponding tool and provider cases. Install or update the CLI at version 1.6.0.1 to use these corrections.
Selecting tools
Section titled “Selecting tools”The command line and the defaultTools setting choose which tools exist and which start on.
| Input | Effect |
|---|---|
--tools a,b |
Allowlist. Only a and b exist, and both start on. * patterns work, such as 'mcp__radius__*'. |
--tools +a,-b |
Changes the default selection: defaultTools, or read,bash,edit,write. Every other tool still exists. Exact names only. |
--tools "" |
No tools. |
--exclude-tools a,b |
Denylist. Removes the tools, MCP tools included. Patterns work. |
--no-tools |
No tools. With --tools, only the tools it names. |
--no-builtin-tools |
No built-in tool starts on. Extension tools that start on by default stay on. |
--no-mcp |
Leaves out the mcp built-in extension, so there are no MCP tools. |
defaultTools: ["a", "b"] |
The tools that start on. Other tools still exist and can be turned on later. |
defaultTools: ["+a", "-b"] |
Changes the inherited selection. In project settings it adds to your list. |
Rules:
- A
--toolslist can’t mix plain names with+nameor-nameentries. - An allowlist keeps MCP tools unless it is empty or one of its entries starts with
mcp__. MCP tools it keeps without naming are only forcodemodeandtool_search. - Unknown tool names are ignored, as in Pi.
/reloadturns on tools newly added todefaultTools. Tools removed from it stay on until the next session.- A resumed session, and
/tree, keep the tools the branch last had on.--tools +a,-bchanges them. Plain--toolsnames,--no-toolsand--no-builtin-toolsreplace them. Extension tools registered since the branch recorded its tools turn on, unless they are off by default.
pisharp --tools read,grep,find,ls -p "Review the code in src/" # read-onlypisharp --tools +codemode # defaults plus codemodepisharp --tools read,bash,codemode,'mcp__radius__*' # one MCP server's toolspisharp --exclude-tools ask_question # one tool offTool policy
Section titled “Tool policy”The tool policy decides how far the built-in tools reach. Pi has no such switch.
| Policy | Effect |
|---|---|
pi (default) |
As described on this page: any path, any command. |
explicit |
Only the paths and commands granted with --allow-*. Plain pisharp has no grants, so file tools refuse every path and bash, grep and find are left out. |
Set it with --tool-policy pi|explicit or the toolPolicy setting. The pisharp session commands use explicit with their grants. Under both policies PiSharp’s own session files, extension manifests and approvals stay protected. See Tool policy.