OpenCode
Open-source multi-provider CLI coding agent with external launch verification and Keychain-backed secret injection.
Last updated
Cloud API TypeScript1. Installation
Prerequisites
- A platform supported by the current OpenCode release
- API key for at least one provider (Anthropic, OpenAI, Google, xAI, Groq)
Install OpenCode
brew install opencode
Install the preferred stack
brew tap nvk/tap
brew install nvk/tap/agent-bondage
brew install nvk/tap/envchain-xtra
brew install nono
Observed on 2026-10-26: Homebrew OpenCode 2.1.4, agent-bondage 0.3.1, envchain-xtra 1.4.1, and upstream nono 0.80.0. OpenCode 2 is no longer the Go-era tool described by the older version of this page.
Verify
opencode --version
bondage --version
nono --version
envchain --help # prints the version header
2. nono Profile
OpenCode's global config is ~/.config/opencode/opencode.json; provider credentials added through /connect live separately under ~/.local/share/opencode/auth.json. In the preferred API-key setup, bondage verifies the OpenCode target first, envchain-xtra injects only the chosen provider keys, and nono limits what the process can touch beyond the project directory.
What the sandbox allows
| Resource | Access | Why |
|---|---|---|
| Current working directory | Read + Write | Project files |
~/.config/opencode/ | Read | Global config, skills, plugins, and commands |
| API endpoints | Network | Provider API calls |
/dev/tty, /dev/null | Read + Write | Terminal I/O |
/dev/urandom | Read | Crypto randomness |
{env:VARIABLE_NAME} substitution. Keep the real value in envchain or another secret manager; the config should contain only the variable reference. If the variable is missing, substitution produces an empty string.
3. envchain-xtra
OpenCode supports many providers. Put only the provider credentials this profile actually needs in its envchain-xtra namespace; do not turn one convenience namespace into a bag of every model key you own.
Store your API keys
# Example: store only the providers used by this profile
envchain --set opencode ANTHROPIC_API_KEY
envchain --set opencode OPENAI_API_KEY
Provider-specific environment names and authentication methods change. Confirm the current OpenCode provider page for the exact integration, then use that name consistently in envchain and the {env:...} reference. For interactive credentials, use /connect and confirm configured accounts with opencode auth list.
Minimal config file (no secret values)
// ~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"providers": {
"anthropic": {
"settings": {
"apiKey": "{env:ANTHROPIC_API_KEY}"
}
}
}
}
4. bondage Wrapper
Add this thin wrapper to your shell config:
opencode() {
bondage exec opencode ~/.config/bondage/bondage.conf -- "$@"
}
Sample stack snippets
Assuming your shared [global] block already exists in ~/.config/bondage/bondage.conf, this is a script-backed OpenCode shape to adapt:
# ~/.config/bondage/bondage.conf
[profile "opencode"]
namespace = opencode
use_envchain = true
use_nono = true
nono_profile = opencode
touch_policy = prompt
target_kind = script
target = /absolute/path/to/opencode/bin/opencode
target_fp = sha256:replace-me
interpreter = /absolute/path/to/node
interpreter_fp = sha256:replace-me
package_root = /absolute/path/to/opencode
package_tree_fp = sha256:replace-me
nono_allow_cwd = true
nono_allow_file = /dev/tty
nono_allow_file = /dev/null
nono_read_file = /dev/urandom
{
"extends": "opencode",
"meta": {
"name": "opencode",
"description": "OpenCode with project-only access and envchain-backed provider keys"
},
"policy": {
"add_deny_access": ["/Volumes"]
},
"workdir": {
"access": "readwrite"
}
}
How it works
The sequence is:
- The shell wrapper passes only the profile name and your arguments
bondageverifies the exact OpenCode targetenvchain-xtraresolves Keychain lookups before the sandbox appliesnonoapplies Seatbelt/Landlock restrictions- OpenCode reads provider keys from env vars — no plaintext file access needed
Reload your shell:
source ~/.zshrc
5. Verification
Test the full chain
bondage verify opencode ~/.config/bondage/bondage.conf
bondage chain opencode ~/.config/bondage/bondage.conf -- --help
opencode --help
Confirm the chosen credential path
# Lists configured provider accounts without printing secret values
opencode auth list
If this profile is envchain-only, do not duplicate the same key through /connect. Keep opencode.json limited to {env:...} references and other non-secret settings.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
| "Invalid authentication credentials" | Environment variable missing, wrong provider name, or stale /connect account |
Check opencode auth list, verify the envchain namespace, and keep the supported {env:...} reference |
| Provider or model missing | Account not connected or provider restricted by config policy | Run /connect or inject the documented environment variable, then inspect enabled/disabled provider settings |
| "Operation not permitted" | nono blocking a path | Check nono why for denied access |