What a tool needs to drive pi headless: json mode, a tools allowlist, a custom agent file
FactVerified 30 Sep 2026Holds anywhere
Fact. A statement and the evidence for it.
Statement#
pi -p --mode json --no-session --no-context-files --no-skills --provider P --model M --thinking L "prompt"prints JSONL. Cost sits in each assistantmessage_endundermessage.usage.cost.total; the final text is in theturn_endmessage. Sum the first, read the last.--tools read,grep,find,ls,Agent,rkb_search,rkb_showis an allowlist that covers built-in, extension and custom tools alike;Agentcomes from@tintinweb/pi-subagents,rkb_*from the rkb extension.- A custom subagent is a file
.pi/agents/<name>.mdin the working directory with frontmattertools,model,thinking,max_turns,run_in_background: false,prompt_mode: replace; extension tools needext:<extension>/<tool>intools. Pass--approveso pi trusts the project files. - pi has no JSON-schema output flag and no cost cap. Ask for one fenced ```json block at the end and parse the last one; cap with a process timeout.
- Providers: OAuth logins live in
~/.pi/agent/auth.json; API keys can come fromOPENROUTER_API_KEYand friends; a custom provider in~/.pi/agent/models.jsonmay use"apiKey": "$ENV_NAME".
Evidence#
- rsrobo pi engine, 2026-09-30, pi 0.99.1, pi-subagents installed. A review of
llnl-asr/dftracer-utils#96withopenai-codex/gpt-6-lunareturned the schema block, ran theverifysubagent and searched rkb; cost $0.04, 342 s, 3 findings, the same 3 that Claude Sonnet 5.5 found for $1.29.
Also found by searching
- pi -p --mode json --tools read,grep,Agent "review" -> JSONL, where is cost and final text?
- I'm scripting the pi coding agent non-interactively and need cost, a tool allowlist and a subagent
- how do I drive pi headless from another tool with JSON output, restricted tools and a custom subagent?
- pi agent has no --json-schema or --max-budget like claude -p; how to cap and parse output, .pi/agents/ file
- how do I run pi -p non-interactively and get JSON output with token cost?
- pi headless mode: restrict tools, define a subagent file, parse final answer
- pi has no --json-schema flag or max budget, how do I get structured output and cap cost?
- drive pi coding agent from a script like claude -p: --mode json, --tools allowlist, .pi/agents/*.md