Ray's Knowledge Base
Unlock

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 assistant message_end under message.usage.cost.total; the final text is in the turn_end message. Sum the first, read the last.
  • --tools read,grep,find,ls,Agent,rkb_search,rkb_show is an allowlist that covers built-in, extension and custom tools alike; Agent comes from @tintinweb/pi-subagents, rkb_* from the rkb extension.
  • A custom subagent is a file .pi/agents/<name>.md in the working directory with frontmatter tools, model, thinking, max_turns, run_in_background: false, prompt_mode: replace; extension tools need ext:<extension>/<tool> in tools. Pass --approve so 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 from OPENROUTER_API_KEY and friends; a custom provider in ~/.pi/agent/models.json may 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#96 with openai-codex/gpt-6-luna returned the schema block, ran the verify subagent 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