Skip to content

👐 OpenCode

OpenCode (opencode) is an open-source agentic coding assistant CLI. It is built to leverage open-source LLMs (like Qwen, DeepSeek, and Llama) locally or via self-hosted APIs, providing developers with privacy-first pair-programming, codebase indexing, and terminal task automation.

For local model commands, see the Ollama Cheat Sheet (M03).


📊 Tool Datasheet

MetricDetails
Tool NameOpenCode
CategoryOpen-Source Local Agentic CLI
PurposeTo offer a privacy-focused, local alternative for terminal-based pair programming and codebase refactoring.
LicenseApache 2.0 / Open Source
Backend ModelsDeepSeek-Coder, Qwen-Coder, CodeLlama (via Ollama or vLLM)
CLI Commandsopencode

🛠️ Capabilities

  1. Privacy-First Execution: Runs entirely on local hardware (via Ollama or local vLLM servers), ensuring zero data leaks to external APIs.
  2. Semantic RAG Indexing: Builds a local vector store database of your repository to answer architectural questions accurately.
  3. Command Execution Sandbox: Proposes file reads, writes, and terminal checks, running safely inside user-approved directories.
  4. Multi-Model Routing: Dynamically switch backend models based on the task (e.g., smaller models for basic refactoring, larger models for complex logic).

🧭 Step-by-Step Tutorial & Setup

This tutorial guides you through installing OpenCode, linking it to a local Ollama model, and indexing a workspace.

1. Prerequisite (Start Local Model Server)

Start Ollama with a coding model:

bash
ollama run qwen2.5-coder:7b

2. Install OpenCode CLI

Use uv to install the tool locally:

bash
conda activate ai_dev
uv pip install opencode-cli

3. Initialize Configuration

Generate the local config folder:

bash
opencode init

Edit your configuration file at ~/.opencode/config.json:

json
{
  "api_type": "ollama",
  "base_url": "http://localhost:11434",
  "model": "qwen2.5-coder:7b",
  "embedding_model": "nomic-embed-text"
}

4. Index Repository & Chat

Build the semantic index of your workspace code and start the interactive terminal session:

bash
opencode index --path ~/AI_BOOTCAMP/labs/my-project
opencode chat

Inside the session, execute:

text
opencode> Write a new helper module in src/utils/validators.py to validate business email formats

💡 Sample Ideation to Test

Try these ideas to expand your OpenCode integration:

  1. Fully Local SDD Pipeline: Configure Specify (Spec Kit) templates to use opencode as the AI provider. Run the entire /speckit.specify and /speckit.implement loops offline using local GPUs.
  2. Autonomous Code Documenter: Create a weekly cron task that runs opencode to scan undocumented Python modules, write docstrings conforming to PEP 257, and output changes directly as pull requests.