Appearance
👐 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
| Metric | Details |
|---|---|
| Tool Name | OpenCode |
| Category | Open-Source Local Agentic CLI |
| Purpose | To offer a privacy-focused, local alternative for terminal-based pair programming and codebase refactoring. |
| License | Apache 2.0 / Open Source |
| Backend Models | DeepSeek-Coder, Qwen-Coder, CodeLlama (via Ollama or vLLM) |
| CLI Commands | opencode |
🛠️ Capabilities
- Privacy-First Execution: Runs entirely on local hardware (via Ollama or local vLLM servers), ensuring zero data leaks to external APIs.
- Semantic RAG Indexing: Builds a local vector store database of your repository to answer architectural questions accurately.
- Command Execution Sandbox: Proposes file reads, writes, and terminal checks, running safely inside user-approved directories.
- 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:7b2. Install OpenCode CLI
Use uv to install the tool locally:
bash
conda activate ai_dev
uv pip install opencode-cli3. Initialize Configuration
Generate the local config folder:
bash
opencode initEdit 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 chatInside 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:
- Fully Local SDD Pipeline: Configure Specify (Spec Kit) templates to use
opencodeas the AI provider. Run the entire/speckit.specifyand/speckit.implementloops offline using local GPUs. - Autonomous Code Documenter: Create a weekly cron task that runs
opencodeto scan undocumented Python modules, write docstrings conforming to PEP 257, and output changes directly as pull requests.