Pi Agent — Background Sub-Agent Dispatch
Run the pi coding agent as a background sub-agent from Claude Code. Pi is a provider-agnostic coding agent that supports 15+ LLM providers and hundreds of models.
Prerequisites
pi CLI installed: npm install -g @mariozechner/pi-coding-agent
- At least one provider configured (pi uses
github-copilot by default on this machine)
Defaults
Always use openai-codex provider with gpt-5.4 model unless the user specifies otherwise. This is pi's configured default and the reason we dispatch to pi — to get a different model family working on the task.
How It Works
The wrapper script (pi-run.py) launches pi in JSON streaming mode, parses events in real-time, and outputs clean progress lines to stderr while collecting the final response into an output file. This means:
- Progress is visible via Claude Code's background task output (tool calls, thinking, turns)
- Verbose JSON is hidden — you see human-readable summaries, not raw events
- Final result lands in a file that can be read without polluting context
Usage
python3 <skill-dir>/scripts/pi-run.py \
--prompt "Your task here" \
--output /path/to/result.md \
--provider github-copilot \
--model claude-sonnet-4 \
--tools read,bash,edit,write \
--thinking high \
--cwd /path/to/project \
--context src/main.ts src/utils.ts
Arguments
| Arg |
Short |
Required |
Description |
--prompt |
-m |
Yes |
The task/prompt for pi |
--output |
-o |
No |
Output file (default: stdout) |
--provider |
-P |
No |
LLM provider (default: pi's configured default) |
--model |
-M |
No |
Model ID |
--tools |
-t |
No |
Comma-separated tools: read, bash, edit, write, grep, find, ls |
--no-tools |
|
No |
Disable all tools (pure Q&A) |
--thinking |
|
No |
Thinking level: off, minimal, low, medium, high, xhigh |
--cwd |
|
No |
Working directory for pi (default: current) |
--system-prompt |
-s |
No |
Custom system prompt |
--context |
-c |
No |
Context files (passed to pi as @file references) |
Available Providers & Models (on this machine)
Pi is configured with github-copilot as the default provider. Key models available:
claude-sonnet-4, claude-sonnet-4.5, claude-sonnet-4.6
claude-opus-4.5, claude-opus-4.6
claude-haiku-4.5
gpt-5, gpt-5.1, gpt-5.2, gpt-5.4
gpt-5.1-codex, gpt-5.1-codex-max
gemini-2.5-pro, gemini-3-flash-preview, gemini-3-pro-preview
Run pi --list-models for the full list.
Workflow
- User requests a task to dispatch to pi, or Claude decides pi would be useful for parallel work
- Confirm with the user before dispatching:
- What prompt/task to send
- Which provider and model to use (recommend based on task type)
- Whether pi should have write access (
--tools) or be read-only
- The working directory (
--cwd) — usually the project root
- Run
pi-run.py in the background using run_in_background: true on the Bash tool
- Inform the user the task is running
- When the background task completes, read the output file to get the result
- Summarize the result for the user without dumping the full content into context unless asked
Model Selection Guidance
Default is openai-codex/gpt-5.4. Only override if the user asks for a specific model.
| Task Type |
Model |
Provider |
| Default (most tasks) |
gpt-5.4 |
openai-codex |
| Large codex-style generation |
gpt-5.1-codex-max |
github-copilot |
| Quick/cheap tasks |
gpt-5-mini |
github-copilot |
| Cross-model validation |
claude-sonnet-4.6 |
github-copilot |
Safety
- For tasks that modify files, ensure
--cwd points to the correct project directory
- Use
--tools read,grep,find,ls for read-only analysis tasks
- Use
--no-tools for pure Q&A where no file access is needed
- Pi has no permission system in its core — it will execute all tool calls without confirmation. Be deliberate about what tools you enable.
Example Invocations
# Background code review with GPT-5
python3 <skill-dir>/scripts/pi-run.py \
--prompt "Review src/ for security vulnerabilities. Focus on input validation and injection risks." \
--output /tmp/pi-security-review.md \
--provider github-copilot --model gpt-5 \
--tools read,grep,find,ls \
--cwd /path/to/project
# Parallel refactoring with Opus
python3 <skill-dir>/scripts/pi-run.py \
--prompt "Refactor the auth module to use JWT tokens instead of session cookies" \
--output /tmp/pi-refactor-result.md \
--provider github-copilot --model claude-opus-4.6 \
--tools read,bash,edit,write \
--thinking high \
--cwd /path/to/project
# Quick question, no tools
python3 <skill-dir>/scripts/pi-run.py \
--prompt "Explain the difference between OAuth 2.0 and OIDC" \
--output /tmp/pi-explanation.md \
--no-tools
1---2name: pi-agent3description: Dispatch tasks to the pi coding agent as a background sub-agent. Use when you want to run a coding task in parallel using a different model/provider (e.g., GPT-5, Gemini, Codex) via the pi CLI. Supports any task pi can handle — code generation, refactoring, analysis, file operations. Progress streams to stderr, final result written to a file. Trigger on requests like "use pi to...", "run this on pi", "dispatch to pi", or when parallel model diversity would help.4---56# Pi Agent — Background Sub-Agent Dispatch78Run the [pi coding agent](https://github.com/badlogic/pi-mono) as a background sub-agent from Claude Code. Pi is a provider-agnostic coding agent that supports 15+ LLM providers and hundreds of models.910## Prerequisites1112- `pi` CLI installed: `npm install -g @mariozechner/pi-coding-agent`13- At least one provider configured (pi uses `github-copilot` by default on this machine)1415## Defaults1617**Always use `openai-codex` provider with `gpt-5.4` model unless the user specifies otherwise.** This is pi's configured default and the reason we dispatch to pi — to get a different model family working on the task.1819## How It Works2021The wrapper script (`pi-run.py`) launches pi in JSON streaming mode, parses events in real-time, and outputs clean progress lines to stderr while collecting the final response into an output file. This means:2223- **Progress is visible** via Claude Code's background task output (tool calls, thinking, turns)24- **Verbose JSON is hidden** — you see human-readable summaries, not raw events25- **Final result lands in a file** that can be read without polluting context2627## Usage2829```bash30python3 <skill-dir>/scripts/pi-run.py \31 --prompt "Your task here" \32 --output /path/to/result.md \33 --provider github-copilot \34 --model claude-sonnet-4 \35 --tools read,bash,edit,write \36 --thinking high \37 --cwd /path/to/project \38 --context src/main.ts src/utils.ts39```4041### Arguments4243| Arg | Short | Required | Description |44|-----|-------|----------|-------------|45| `--prompt` | `-m` | Yes | The task/prompt for pi |46| `--output` | `-o` | No | Output file (default: stdout) |47| `--provider` | `-P` | No | LLM provider (default: pi's configured default) |48| `--model` | `-M` | No | Model ID |49| `--tools` | `-t` | No | Comma-separated tools: read, bash, edit, write, grep, find, ls |50| `--no-tools` | | No | Disable all tools (pure Q&A) |51| `--thinking` | | No | Thinking level: off, minimal, low, medium, high, xhigh |52| `--cwd` | | No | Working directory for pi (default: current) |53| `--system-prompt` | `-s` | No | Custom system prompt |54| `--context` | `-c` | No | Context files (passed to pi as @file references) |5556### Available Providers & Models (on this machine)5758Pi is configured with `github-copilot` as the default provider. Key models available:5960- `claude-sonnet-4`, `claude-sonnet-4.5`, `claude-sonnet-4.6`61- `claude-opus-4.5`, `claude-opus-4.6`62- `claude-haiku-4.5`63- `gpt-5`, `gpt-5.1`, `gpt-5.2`, `gpt-5.4`64- `gpt-5.1-codex`, `gpt-5.1-codex-max`65- `gemini-2.5-pro`, `gemini-3-flash-preview`, `gemini-3-pro-preview`6667Run `pi --list-models` for the full list.6869## Workflow70711. User requests a task to dispatch to pi, or Claude decides pi would be useful for parallel work722. **Confirm with the user** before dispatching:73 - What prompt/task to send74 - Which provider and model to use (recommend based on task type)75 - Whether pi should have write access (`--tools`) or be read-only76 - The working directory (`--cwd`) — usually the project root773. Run `pi-run.py` **in the background** using `run_in_background: true` on the Bash tool784. Inform the user the task is running795. When the background task completes, read the output file to get the result806. Summarize the result for the user without dumping the full content into context unless asked8182### Model Selection Guidance8384Default is `openai-codex/gpt-5.4`. Only override if the user asks for a specific model.8586| Task Type | Model | Provider |87|-----------|-------|----------|88| Default (most tasks) | `gpt-5.4` | `openai-codex` |89| Large codex-style generation | `gpt-5.1-codex-max` | `github-copilot` |90| Quick/cheap tasks | `gpt-5-mini` | `github-copilot` |91| Cross-model validation | `claude-sonnet-4.6` | `github-copilot` |9293### Safety9495- For tasks that modify files, ensure `--cwd` points to the correct project directory96- Use `--tools read,grep,find,ls` for read-only analysis tasks97- Use `--no-tools` for pure Q&A where no file access is needed98- Pi has **no permission system** in its core — it will execute all tool calls without confirmation. Be deliberate about what tools you enable.99100## Example Invocations101102```bash103# Background code review with GPT-5104python3 <skill-dir>/scripts/pi-run.py \105 --prompt "Review src/ for security vulnerabilities. Focus on input validation and injection risks." \106 --output /tmp/pi-security-review.md \107 --provider github-copilot --model gpt-5 \108 --tools read,grep,find,ls \109 --cwd /path/to/project110111# Parallel refactoring with Opus112python3 <skill-dir>/scripts/pi-run.py \113 --prompt "Refactor the auth module to use JWT tokens instead of session cookies" \114 --output /tmp/pi-refactor-result.md \115 --provider github-copilot --model claude-opus-4.6 \116 --tools read,bash,edit,write \117 --thinking high \118 --cwd /path/to/project119120# Quick question, no tools121python3 <skill-dir>/scripts/pi-run.py \122 --prompt "Explain the difference between OAuth 2.0 and OIDC" \123 --output /tmp/pi-explanation.md \124 --no-tools125```