OpenCode Cheatsheet

AI-Assisted Programming for PhD Researchers

OpenCode evolves fast, and this sheet matches the version we install together on Day 1. If a command below doesn’t behave as described, run opencode --help and check the official docs.

Install / update

Command What it does
curl -fsSL https://opencode.ai/install \| bash Installs OpenCode (macOS/Linux)
brew install anomalyco/tap/opencode Installs OpenCode via Homebrew (macOS)
opencode upgrade Updates OpenCode to the latest version (verify with opencode --help if this changed)

Start

Command What it does
opencode Launches the terminal UI in the current project (run from the project root)
opencode auth login Stores an API key for a model provider (e.g. Mistral); in some versions this is the in-session /connect command; check opencode --help

In-session

Key / command What it does
Tab Toggles between Plan mode (read-only, suggests changes) and Build mode (executes changes)
/undo Reverts the last change OpenCode made
/redo Re-applies a change you just undid
/compact Compacts the conversation history to free up context
/init Scans the repo and generates/updates AGENTS.md with project context
@file References a specific file in your message (e.g. @src/main.py)
!command Runs a shell command directly from the chat

/init, /undo, /redo, and /compact are built-in commands but can be overridden by a same-named file in .opencode/commands/. Check opencode --help if a command listed here has changed.

Config (opencode.json)

Project-level configuration lives in opencode.json at the repository root.

If you connected Mistral with opencode auth login (Lecture III), you do not need the provider block below: your key is already stored and the model is selectable in-session. Pasting it in expects a MISTRAL_API_KEY environment variable that the course never sets, which breaks a working setup. Copy only the model line if you want to pin the default model.

A minimal example selecting a model and adding Mistral as a provider by hand:

{
  "$schema": "https://opencode.ai/config.json",
  "model": "mistral/mistral-medium-latest",
  "provider": {
    "mistral": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Mistral",
      "options": {
        "baseURL": "https://api.mistral.ai/v1",
        "apiKey": "{env:MISTRAL_API_KEY}"
      },
      "models": {
        "mistral-medium-latest": { "name": "Mistral Medium 3.5" }
      }
    }
  }
}

OpenCode may ship a native Mistral provider (selectable via /connect) in a newer version; check opencode --help / the providers docs if a native block is available instead of the openai-compatible shim above.

A permission block controls which actions run automatically vs. need your approval ("allow" / "ask" / "deny", last matching rule wins):

{
  "permission": {
    "bash": { "*": "ask", "git *": "allow", "rm *": "deny" },
    "edit": "ask"
  }
}

MCP (opencode.json)

MCP (Model Context Protocol) servers add external tools. A server is either remote (a hosted URL) or local (a command OpenCode launches). Lab 5 wires Context7, which looks up current library documentation:

{
  "mcp": {
    "context7": {
      "type": "remote",
      "url": "https://mcp.context7.com/mcp",
      "enabled": true
    }
  }
}

GitHub’s hosted server has the same shape at https://api.githubcopilot.com/mcp/, but needs opencode mcp auth github first. Keep any token you give it read-only.

A local server takes a launch command instead: "type": "local", "command": ["npx", "-y", "<package>"], with an optional "environment": { "API_KEY": "{env:VAR}" }. Authenticate a server that needs it with opencode mcp auth <name>.

Command What it does
opencode mcp list Lists configured MCP servers
opencode mcp auth <server-name> Authenticates with an MCP server
opencode mcp logout <server-name> Removes stored credentials for an MCP server

Skills / commands

OpenCode discovers Claude Code-compatible skills directly, no conversion needed. It looks for SKILL.md files at:

  • .claude/skills/<name>/SKILL.md (project) or ~/.claude/skills/<name>/SKILL.md (global)
  • .opencode/skills/<name>/SKILL.md (project, native) or ~/.config/opencode/skills/<name>/SKILL.md (global, native)

To install a skill, copy its folder into .claude/skills/ in your project. The course ships writing skills under skills/writing/, used in Lab 5; cp -r skills/writing/* .claude/skills/ installs all of them. Leave the trailing slash off the glob: skills/writing/*/ copies the folders’ contents instead of the folders on macOS.

Custom slash commands work the same way: markdown files with YAML frontmatter under .opencode/commands/ (filename becomes the command name, e.g. test.md/test).

Skill and command discovery paths are version-sensitive. Verify against the current OpenCode skills docs if this sheet feels out of date.