NAME
opencode.json — instruction file for OpenCode
SYNOPSIS
~/.config/opencode/
./opencode.json
METADATA
DESCRIPTION
opencode.json is the configuration file for OpenCode, an open-source terminal-based AI coding assistant. It uses standard JSON format to define model preferences, scoped instructions, tool permissions, and MCP server integrations.
The file supports a powerful instruction system where each instruction can be globally applied or scoped to specific file patterns using glob arrays. This allows different coding conventions for different parts of the codebase without separate rule files.
Project-level opencode.json overrides the global configuration at ~/.config/opencode/. The file is designed to be committed to version control so teams share consistent AI assistant behavior.
Lower numbers load first. Higher-priority files override lower ones.
STRUCTURE
ANNOTATED EXAMPLE
1{
2 "model": "anthropic/claude-sonnet-4-20250514",
3 "instructions": [
4 {
5 "content": "Use TypeScript strict mode. Prefer functional patterns."
6 },
7 {
8 "glob": ["src/components/**/*.tsx"],
9 "content": "Use functional React components with named exports."
10 },
11 {
12 "glob": ["**/*.test.ts"],
13 "content": "Use Vitest with describe/it blocks. Prefer userEvent over fireEvent."
14 }
15 ],
16 "permissions": {
17 "autoApprove": ["Read", "Glob", "Grep"],
18 "requireApproval": ["Bash", "Write"]
19 },
20 "mcpServers": {
21 "postgres": {
22 "command": "npx",
23 "args": ["-y", "@modelcontextprotocol/server-postgres"],
24 "env": {
25 "DATABASE_URL": "postgresql://localhost:5432/mydb"
26 }
27 }
28 }
29}
COMMON MISTAKES
Unlike many modern config files, OpenCode uses strict JSON. JSONC (JSON with comments) is not supported. Ensure your editor validates the file as standard JSON.
The instructions field is structured as an array, not a simple string. Each instruction object has a `content` string and an optional `glob` array for file-pattern scoping.
Shell-style $VAR expansion does not work in opencode.json. Environment variables for MCP servers must be specified in the dedicated `env` object within each server configuration.