OpenCode Reference¶
Complete guide to using OpenCode with Preloop's Safety Layer.
Overview¶
OpenCode is an open-source terminal AI coding agent that supports MCP servers natively. It works with multiple LLM providers (OpenAI, Anthropic, Google, etc.) and connects to Preloop for tool governance.
Installation¶
Or via npm:
Verify:
Configuration¶
Connect to Preloop¶
Step 1: Get Your API Key
- Log in to preloop.ai
- Settings → API Keys → + Create API Key
- Name: "OpenCode"
- Copy the key
Step 2: Add Preloop MCP Server
Edit ~/.config/opencode/config.json:
{
"mcpServers": {
"preloop": {
"url": "https://preloop.ai/mcp/v1",
"headers": {
"Authorization": "Bearer YOUR_API_KEY_HERE"
}
}
}
}
Step 3: Verify Connection
You should see Preloop tools listed alongside any other configured tools.
Usage¶
Basic Usage¶
The approval flow is identical to other MCP clients:
- OpenCode sends the tool call to Preloop
- Preloop creates an approval request
- You approve via dashboard, mobile, or email
- Tool executes and result is returned
Key Differences¶
| Feature | OpenCode | Claude Code |
|---|---|---|
| Provider | Multi-provider | Anthropic |
| Language | Go | Node.js |
| Config location | ~/.config/opencode/config.json |
~/.claude/mcp-servers.json |
| MCP support | Native | Native |
| Open source | Yes | Partial |
Automatic Discovery¶
Use the Preloop CLI to automatically detect OpenCode:
This scans ~/.config/opencode/config.json and inspects the local MCP and model configuration.
Discovery is the entry point for onboarding an existing OpenCode setup into Preloop:
- Existing MCP tools can be imported into your Preloop account when they can be represented there
- Existing AI model metadata can be imported or reused when the local configuration is compatible
- Supported managed rewrites can point OpenCode to the Preloop Gateway for model traffic and the Preloop Tool Firewall for governed MCP access
If you want discovery to stay non-mutating in scripts or CI, use the read-only flags supported by the Preloop CLI.