OpenCode vs. Pi AI

This article compares two open-source AI coding agents: OpenCode (anomalyco/opencode) and Pi (earendil-works/pi). Both are powerful tools for AI-assisted development, but they differ significantly in architecture, features, and target audience.

Overview

Feature OpenCode Pi
Type Full AI coding agent application Agent harness/framework
Architecture Monolithic (TUI, CLI, desktop, IDE) Modular (pi-ai, pi-agent-core, pi-coding-agent, pi-tui)
GitHub Stars 195K+ 96.3K+
Monthly Users 16M+ N/A
License MIT MIT
1
2
3
4
5
6
7
8
9
10
11
12
13
OpenCode: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β”‚  TUI  β”‚  Desktop  β”‚  IDE  β”‚  Web   β”‚
          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Pi:       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β”‚ pi-ai    β”‚  β”‚ pi-coding-agent (CLI) β”‚
          β”‚ (LLM API)β”‚  β”‚   + pi-agent-core     β”‚
          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                         β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”
                         β”‚ pi-tui  β”‚
                         β”‚ (TUI)   β”‚
                         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Architecture & Core Concepts

OpenCode

A complete, end-user application with multiple interfaces:

  • Terminal UI (TUI) for interactive coding
  • Desktop app for macOS, Windows, and Linux
  • IDE extensions for VS Code and JetBrains
  • Web interface accessible via browser
  • Server mode for headless operation

Pi

A modular framework designed for extensibility:

  • pi-ai: Unified multi-provider LLM API
  • pi-agent-core: Agent runtime with tool calling and state management
  • pi-coding-agent: Interactive coding agent CLI
  • pi-tui: Terminal UI library with differential rendering

Pi keeps the core small and pushes workflow-specific behavior into TypeScript extensions, skills, prompt templates, and packages.

Command Reference

Starting & Sessions

Action OpenCode Pi
Start interactive opencode pi
Non-interactive opencode run "prompt" pi -p "prompt"
Continue last session opencode --continue pi -c
Browse sessions opencode session list pi -r, /resume
Rename session /name in TUI /name <name>
Fork session /fork in TUI /fork
Clone session /clone in TUI /clone
Export session opencode export <id> /export [file]
Share session /share in TUI /share (GitHub Gist)

Model & Thinking

Action OpenCode Pi
Switch model /models in TUI /model
Change thinking level Variants (high/low/medium) /thinking <level>
List models opencode models pi --list-models

Context Management

Action OpenCode Pi
Manual compaction /compact /compact [prompt]
Tree navigation session_child_* keybinds /tree
Branch summary Automatic Automatic at /tree

Built-in Tools

OpenCode Built-in Tools

  • read, write, edit (file operations)
  • bash (shell commands)
  • grep, glob (search and find)
  • lsp (experimental, code intelligence)
  • apply_patch (apply diffs)
  • skill (load skills)
  • todowrite (task management)
  • webfetch, websearch (online resources)
  • question (ask user questions)

Pi Built-in Tools

  • read, write, edit, bash, grep, find, ls
  • Custom tools via TypeScript extensions
  • MCP servers via extensions

Agents (Specialized Assistants)

OpenCode Agents

OpenCode has built-in agents that can be switched during a session:

Agent Mode Description
Build Primary Default agent with all tools enabled
Plan Primary Analysis and planning (restricted edits)
General Subagent Multi-step tasks with full tool access
Explore Subagent Read-only codebase exploration
Scout Subagent External docs and dependency research

Usage:

  • Switch primary agents: Tab or configured switch_agent keybind
  • Invoke subagents: @agent-name in messages
  • Navigate child sessions: session_child_cycle (Right/Left), session_parent (Up)

Pi Agents

Pi does not have built-in agents. All agent behavior is implemented via TypeScript extensions.

Configuration

OpenCode Config

Format: JSON/JSONC
Locations: Remote β†’ Global β†’ Custom β†’ Project β†’ Managed
Schema: https://opencode.ai/config.json

1
2
3
4
5
6
7
8
9
10
11
12
{
  "$schema": "https://opencode.ai/config.json",
  "model": "anthropic/claude-sonnet-4-5",
  "agent": {
    "build": { "mode": "primary" },
    "plan": { "mode": "primary", "permission": { "edit": "deny" } }
  },
  "permission": { "edit": "ask", "bash": "allow" },
  "mcp": { "sentry": { "type": "remote", "url": "..." } },
  "formatter": { "prettier": { "disabled": true } },
  "lsp": { "typescript": { "disabled": true } }
}

Pi Config

Format: JSON
Locations: Project β†’ Global
No official schema

1
2
3
4
5
6
7
8
{
  "defaultProvider": "anthropic",
  "defaultModel": "claude-sonnet-4-20250514",
  "defaultThinkingLevel": "medium",
  "compaction": { "enabled": true, "reserveTokens": 16384 },
  "retry": { "enabled": true, "maxRetries": 3 },
  "packages": ["pi-skills"]
}

Environment Variables

OpenCode:

  • OPENCODE_CONFIG, OPENCODE_TUI_CONFIG
  • OPENCODE_SERVER_PASSWORD, OPENCODE_SERVER_USERNAME
  • OPENCODE_ENABLE_EXA (websearch)
  • OPENCODE_EXPERIMENTAL_LSP_TOOL (LSP tool)

Pi:

  • ANTHROPIC_API_KEY, OPENAI_API_KEY, etc.
  • PI_CODING_AGENT_SESSION_DIR
  • PI_SKIP_VERSION_CHECK=1 (disable version check)
  • PI_OFFLINE=1 (disable network operations)

Permissions & Security

OpenCode Permissions

Default: "allow" (all tools enabled)
Values: "allow", "ask", "deny"

1
2
3
4
5
6
7
8
{
  "permission": {
    "*": "ask",
    "bash": { "*": "allow", "git *": "allow", "rm *": "deny" },
    "edit": "deny",
    "external_directory": { "~/projects/**": "allow" }
  }
}

Features:

  • Auto mode (--auto) to auto-approve non-denied actions
  • Per-agent permission overrides
  • Glob pattern matching for granular control

Pi Security

No built-in permission system - runs with user permissions
Project Trust System:

  • Controls loading of project-local settings and resources
  • defaultProjectTrust: "ask" (default), "always", or "never"
  • Trust decisions stored in ~/.pi/agent/trust.json

Containerization Options:

  • Gondolin: Route built-in tools into a local micro-VM
  • Plain Docker: Run whole pi process in container
  • OpenShell: Policy-controlled sandbox (filesystem, process, network controls)

Provider & Model Support

Feature OpenCode Pi
Provider Count 75+ (Models.dev) 999+ (Models.dev)
OAuth Support GitHub Copilot, Claude Pro/Max, etc. ChatGPT Plus/Pro, Claude Pro/Max, etc.
API Key Support Yes Yes
Custom Provider JSON config TypeScript extensions
Local Models Ollama, LM Studio, vLLM llama.cpp
Model Cycling Ctrl+P Ctrl+P
Model Variants high/low/medium/custom thinking levels (off/minimal/low/medium/high/xhigh/max)

Session Management

OpenCode Session Storage

~/.local/share/opencode/
Format: JSON
File: session_<id>.json

Pi Session Storage

~/.pi/agent/sessions/
Format: JSONL (tree structure)
File: <timestamp>_<uuid>.jsonl

Session Format Comparison

1
2
3
4
5
6
7
8
9
10
11
12
OpenCode (JSON):
{
  "id": "uuid",
  "messages": [...],
  "metadata": {...}
}

Pi (JSONL - Tree Structure):
{"type":"session","version":3,"id":"uuid","timestamp":"...","cwd":"..."}
{"type":"message","id":"a1b2c3d4","parentId":null,"timestamp":"...","message":{...}}
{"type":"message","id":"b2c3d4e5","parentId":"a1b2c3d4","timestamp":"...","message":{...}}
{"type":"compaction","id":"f6g7h8i9","parentId":"e5f6g7h8","timestamp":"...","summary":"...","firstKeptEntryId":"..."}

Erweiterbarkeit (Extensibility)

OpenCode Extensions

  • Plugins: opencode plugin <module>
  • Skills: .opencode/skills/*/SKILL.md (YAML frontmatter)
  • Agents: .opencode/agents/ (JSON or Markdown)
  • Commands: .opencode/commands/ (Markdown templates)
  • Themes: TUI themes
  • LSP Servers: JSON config
  • MCP Servers: JSON config

Pi Extensions

  • TypeScript Extensions: pi -e ./extension.ts
  • Skills: TypeScript Skills
  • Prompt Templates: TypeScript
  • Themes: TypeScript
  • Custom Tools: pi.registerTool()
  • Custom Commands: pi.registerCommand()
  • Custom Providers: pi.registerProvider()

Example Pi Extension:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";

export default function (pi: ExtensionAPI) {
  pi.on("tool_call", async (event, ctx) => {
    if (event.toolName === "bash" && event.input.command?.includes("rm -rf")) {
      const ok = await ctx.ui.confirm("Dangerous!", "Allow rm -rf?");
      if (!ok) return { block: true, reason: "Blocked by user" };
    }
  });

  pi.registerTool({
    name: "greet",
    label: "Greet",
    description: "Greet someone by name",
    async execute(toolCallId, params, signal, onUpdate, ctx) {
      return { content: [{ type: "text", text: `Hello, ${params.name}!` }], details: {} };
    }
  });
}

Installation & Deployment

OpenCode Installation

Method Command
Install Script curl -fsSL https://opencode.ai/install \| bash
npm npm install -g opencode-ai
Homebrew brew install anomalyco/tap/opencode
Chocolatey choco install opencode
Scoop scoop install opencode
Docker docker run -it --rm ghcr.io/anomalyco/opencode
Arch Linux sudo pacman -S opencode

Pi Installation

Method Command
Install Script curl -fsSL https://pi.dev/install.sh \| sh
npm npm install -g @earendil-works/pi-coding-agent
Docker Custom Dockerfile required

When to Use Which

Choose OpenCode if you want:

  • βœ… A complete, out-of-the-box application
  • βœ… TUI, desktop app, IDE extension, and web interface
  • βœ… Built-in agents (Build, Plan, General, Explore, Scout)
  • βœ… Extensive configuration options (JSON/JSONC)
  • βœ… 16M+ monthly users and active community
  • βœ… Auto-update, snapshot system, formatters
  • βœ… GitHub integration (GitHub Agent)

Choose Pi if you want:

  • βœ… A modular framework for AI agents
  • βœ… TypeScript extensions for deep customization
  • βœ… Fine-grained control over agent behavior
  • βœ… Project trust system for security
  • βœ… Containerization options (Gondolin, Docker, OpenShell)
  • βœ… JSONL session format with tree structure
  • βœ… Branching and compaction built-in
  • βœ… To build custom agent workflows

Summary

OpenCode is a full-featured AI coding agent application designed for end users who want a complete solution with multiple interfaces (TUI, desktop, IDE, web) and built-in agents for different workflows. It emphasizes usability, with extensive configuration, auto-updates, and a large user community.

Pi is a modular agent harness/framework designed for developers who want to build custom AI agent workflows. It provides a clean, extensible architecture with TypeScript extensions, fine-grained control over agent behavior, and robust containerization options for security.

Both are open-source (MIT license) and support 75-999+ LLM providers through Models.dev, but they serve different audiences and use cases.

See Also

For more information about AI coding agents, see the AI Agents introduction article.