OpenCode Guide
Overview
OpenCode is an open-source terminal AI programming tool that supports multiple model providers. By configuring shallowseek's API endpoint, you can use OpenCode to access the platform's models for coding and project management.
Install OpenCode
npm Global Install (Recommended)
npm install -g opencode-ai
Run Directly (No Install Required)
npx opencode-ai
Verify Installation
opencode --version
Configure shallowseek API
OpenCode uses a TOML configuration file and supports multiple profile switching:
Create Configuration File
mkdir -p ~/.config/opencode
Configuration Example (~/.config/opencode/config.toml)
# shallowseek configuration
[profile.shallowseek]
base_url = "https://api.shallowseek.top/"
api_key = "sk-your-api-key-here"
model = "gpt-4o"
# Use shallowseek by default
[default]
profile = "shallowseek"
You can also configure via environment variables:
# Linux / macOS
export OPENAI_BASE_URL="https://api.shallowseek.top/"
export OPENAI_API_KEY="sk-your-api-key-here"
# Windows (PowerShell)
$env:OPENAI_BASE_URL="https://api.shallowseek.top/"
$env:OPENAI_API_KEY="sk-your-api-key-here"
OpenCode uses the OpenAI-compatible interface. You can set the API address and key via a TOML configuration file or environment variables. The configuration file approach supports multiple profiles, making it easy to switch between different models.
Basic Usage
Interactive Mode
cd /path/to/your/project
opencode
Single Query
opencode -p "Explain the directory structure of this project"
opencode -p "Write a health check endpoint for a REST API"
Specify Model
opencode --model gpt-4o
opencode --model claude-sonnet-4-20250514
Common Commands
| Command | Description |
|---|---|
opencode | Start interactive mode |
opencode -p "question" | Single query |
opencode --model name | Specify model |
opencode --profile name | Switch configuration profile |
opencode --help | View help |
Tips & Tricks
- Multi-profile switching — Create different profiles for different projects to quickly switch models and configurations
- Run in the project directory — OpenCode reads the project context for more accurate suggestions
- Use git protection — Commit before modifying code to make rollback easy
- Review diffs — OpenCode shows changes after modifying files; carefully review before confirming
- Leverage single-query mode — Use
-psingle-query mode for simple questions, which is more efficient
FAQ
How do I confirm OpenCode is connected to shallowseek?
Check the configuration file ~/.config/opencode/config.toml to confirm base_url points to https://api.shallowseek.top/. Run a simple test to verify the connection is working.
What if the configuration file doesn't take effect?
- Confirm the configuration file path is correct (
~/.config/opencode/config.toml) - Check for correct TOML syntax (pay attention to quotes and indentation)
- Ensure the API Key has no extra spaces or newlines
- Use the
--profileparameter to explicitly specify a profile
How does OpenCode differ from Codex CLI / Claude Code?
All three are terminal AI programming assistants. OpenCode is an open-source project that supports multiple providers and multi-profile switching via TOML configuration files, offering more flexible configuration. shallowseek supports all three tools.