Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pi plugin for Claude Code

Use Pi (the earendil-works/pi coding agent, running GLM by default) from inside Claude Code for code reviews or to delegate tasks.

Pi runs in RPC mode (pi --mode rpc): the plugin spawns a Pi process, speaks the JSONL protocol over stdin/stdout, and waits for agent_settled before reading the result. This gives clean abort, real session resume, and native Pi session transfer — improvements over a plain CLI-spawn approach.

It is intended for Claude Code users who want a second model — GLM via Pi — to review their work or take on delegated tasks.

What You Get

  • /pi:review for a read-only code review
  • /pi:adversarial-review for a steerable challenge review
  • /pi:rescue, /pi:transfer, /pi:status, /pi:result, and /pi:cancel to delegate work, hand off sessions, and manage background jobs

Requirements

  • Pi CLI installed (see https://pi.dev)
  • A configured Pi provider for GLM. The default model is zai/glm-5.1.
  • Node.js 18.18 or later

Install

1. Set up Pi with a GLM provider

Pi talks to GLM through the zai provider. Set the API key as an environment variable:

export ZAI_API_KEY="your-zai-coding-plan-key"

Verify Pi can see the model:

pi --version
# then in an interactive Pi session, /models should list zai/glm-5.1

Note on provider/model ids: Pi registers the ZAI Coding Plan provider as zai, so the full model id is zai/glm-5.1 (passed to the plugin as --model zai/glm-5.1 or set via PI_PLUGIN_MODEL). The zai-coding-cn provider points at the domestic endpoint.

2. Install the plugin in Claude Code

Add the marketplace:

/plugin marketplace add cuongducle/pi-plugin-cc

Install the plugin:

/plugin install pi@cuongducle-pi

Reload plugins:

/reload-plugins

3. Verify

/pi:setup

/pi:setup checks whether Pi is installed and the runtime is ready. There is no separate login step if ZAI_API_KEY is set; otherwise run pi interactively and use /login.

After install you should see the slash commands listed below and the pi:pi-rescue subagent in /agents.

A simple first run:

/pi:review --background
/pi:status
/pi:result

Usage

/pi:review

Runs a read-only code review of your current work by handing the diff to GLM and asking for structured findings.

Use --base <ref> for branch review. It also supports --wait and --background.

/pi:review
/pi:review --base main
/pi:review --background

Note

Code review for multi-file changes may take a while. It is generally recommended to run it in the background.

The review prompt asks GLM to return a strict JSON object (verdict, summary, findings, next_steps). The parser also tolerates models that wrap the JSON in prose or markdown fences — it scans every fenced block and balanced {...} substring and picks the first that both parses and matches the review shape.

/pi:adversarial-review

Runs a steerable review that questions the chosen implementation and design. It supports --base <ref>, --wait, --background, and extra focus text after the flags.

/pi:adversarial-review --base main challenge whether this was the right caching and retry design
/pi:adversarial-review --background look for race conditions and question the chosen approach

/pi:rescue

Hands a task to Pi through the pi:pi-rescue subagent. It supports --background, --wait, --resume, --fresh, and --model. Add --write for a write-capable run (the subagent defaults to write-capable unless you ask for read-only behavior).

/pi:rescue investigate why the tests started failing
/pi:rescue fix the failing test with the smallest safe patch
/pi:rescue --resume apply the top fix from the last run
/pi:rescue --model zai/glm-5.1 investigate the flaky integration test
/pi:rescue --background investigate the regression

Notes:

  • If you do not pass --model, the default (zai/glm-5.1, or whatever PI_PLUGIN_MODEL is set to) is used.
  • Follow-up rescue requests can continue the latest Pi task in the repo via --resume.

/pi:transfer

Writes a real Pi session file from the current Claude Code transcript so you can continue the conversation natively in Pi. Unlike a prompt-seed, this emits a valid Pi session JSONL (header + chained user/assistant message entries) that Pi loads via pi --session <path>.

/pi:transfer
/pi:transfer --source ~/.claude/projects/-Users-me-repo/<session-id>.jsonl

Note

The continuation is not byte-for-byte identical to the Claude session (tool calls/results are summarized into text), but Pi sees the full turn history and can continue from there.

/pi:status

Shows running and recent Pi jobs for the current repository.

/pi:status
/pi:status task-abc123

/pi:result

Shows the final stored Pi output for a finished job. When available it includes the Pi session id so you can reopen that run with pi --session <id>.

/pi:result
/pi:result task-abc123

/pi:cancel

Cancels an active background Pi job. The plugin sends a Pi RPC abort and terminates the worker process tree.

/pi:cancel
/pi:cancel task-abc123

/pi:setup

Checks whether Pi is installed. If Pi is missing it can offer to install it for you.

Configuration

Default model

export PI_PLUGIN_MODEL="zai/glm-5.1"

You can also pass --model <provider/model> to /pi:rescue and the review commands for a one-off override.

How it works

Each task or review spawns a fresh pi --mode rpc process. The companion speaks the JSONL RPC protocol:

  1. Sends {"type":"prompt","message":"..."} — the success response only means "accepted", not "done".
  2. Streams events (message_update, tool_execution_*, turn_end).
  3. Waits for {"type":"agent_settled"} — the authoritative stop signal (NOT agent_end, which may be followed by retry/compaction/queued follow-ups).
  4. Retrieves the final answer via get_last_assistant_text.
  5. Aborts via {"type":"abort"} (clean cancel) and closes stdin.

stdout is split on LF only (NOT readline — U+2028/U+2029 are legal inside JSON strings and would corrupt framing). Job state (status, session id, logs) is persisted per workspace so /pi:status, /pi:result, and /pi:cancel work across foreground and background runs.

Pi has no permission gate in RPC mode — bash/edit/write run non-interactively by default. The plugin launches Pi with --no-extensions --no-skills so no extension can block on a UI request, and restricts tools to read,grep,find,ls,bash for review/read-only runs.

Differences from codex-plugin-cc and opencode-plugin-cc

Aspect codex-plugin-cc opencode-plugin-cc pi-plugin-cc
Backend Codex CLI (GPT) opencode CLI (GLM) Pi RPC mode (GLM)
Transport JSON-RPC app server opencode run NDJSON pi --mode rpc JSONL
Cancel turn/interrupt RPC kill process {"type":"abort"} (clean)
Done signal turn/completed process exit agent_settled (precise)
Resume codex resume --session switch_session + JSONL
Transfer native import summarize → prompt write real Pi session JSONL
Permissions approval policy --auto no gate (RPC default)

License

Apache-2.0. See NOTICE.

About

Use Pi (GLM via RPC mode) from Claude Code to review code or delegate tasks.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages