Welcome to the OpenCode startup guide! This repository will help you get started with OpenCode as a powerful coding assistant and set up essential tools like Context7 MCP.
OpenCode is an interactive CLI tool that helps developers with software engineering tasks. It provides intelligent code assistance, file management, and integration with various development tools.
The easiest way to get started is to run our installation script:
./install.shThis script will:
- β Install OpenCode globally
- β Set up secure configuration
- β Configure Context7 MCP for up-to-date documentation
- β Prompt for your Context7 API key (optional)
- β Create necessary directories and symlinks
- β Verify the installation
If you prefer to install manually, follow these steps:
- Node.js (version 16 or higher)
- npm or yarn package manager
npm install -g opencode-ai@latestopencode --version# Create the global config directory if it doesn't exist
mkdir -p ~/.config/opencode
# Copy the base configuration
cp config/opencode.json ~/.config/opencode/opencode.jsonFor higher rate limits with Context7:
# Create secrets directory
mkdir -p secrets
# Create your API key file
echo "your_api_key_here" > secrets/context7-key
chmod 600 secrets/context7-keyOnce installed, you can start using OpenCode in any project directory:
cd your-project
opencodeContext7 MCP provides up-to-date code documentation for LLMs and AI code editors. It pulls current, version-specific documentation and code examples directly from the source.
You can install Context7 MCP either as a remote server (recommended) or locally:
Add this to your opencode.json configuration file:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"context7": {
"type": "remote",
"url": "https://mcp.context7.com/mcp"
}
}
}If you sign up for a free account at context7.com/dashboard, you can get higher rate limits:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"context7": {
"type": "remote",
"url": "https://mcp.context7.com/mcp",
"headers": {
"CONTEXT7_API_KEY": "{env:CONTEXT7_API_KEY}"
}
}
}
}Set the environment variable:
export CONTEXT7_API_KEY=your_api_key_here{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"context7": {
"type": "local",
"command": ["npx", "-y", "@upstash/context7-mcp"]
}
}
}Add use context7 to your prompts to automatically fetch up-to-date documentation:
Create a Next.js middleware that checks for a valid JWT in cookies and redirects unauthenticated users to /login. use context7
Context7 MCP provides these tools:
resolve-library-id: Find the correct Context7 library IDget-library-docs: Fetch documentation for a specific library
Add this to your AGENTS.md file to automatically use Context7 when needed:
When you need code generation, setup steps, or library/API documentation, automatically use Context7 MCP tools to resolve library id and get library docs.
/help- Get help with using OpenCodeopencode- Start OpenCode in current directory- Use natural language to request code changes, file operations, or explanations
"Create a new React component for user profiles"
"Refactor this function to be more efficient"
"Add tests for the authentication service"
"Explain how this algorithm works"
The installation sets up a secure OpenCode configuration with:
- π Safe Permissions: Set to "ask" for
edit,bash, andwebfetchoperations - π Context7 MCP: Pre-configured for up-to-date code documentation
- π Instructions: Includes this README and AGENTS.md for context
- π¨ Theme: Uses the default "opencode" theme
- π Autoupdate: Enabled to keep OpenCode current
- π Secure Storage: API keys stored in restricted files (chmod 600)
- π Symlinked Secrets:
~/.secrets/opencode-demoβ./secrets/ - π« Git-Safe: Secret files excluded from version control
- π Isolated Configuration: Separate from project files
After installation, you'll have:
opencode-demo/
βββ secrets/
β βββ context7-key # Your API key (gitignored)
βββ config/
β βββ opencode.json # Configuration template
βββ install.sh # Installation script
~/.config/opencode/
βββ opencode.json # Your active configuration
~/.secrets/
βββ opencode-demo/ # Symlink to repo secrets/
βββ context7-key
Free Tier: Works without an API key with standard rate limits
Higher Limits: Sign up at context7.com/dashboard for:
- Increased rate limits
- Access to private repositories
- Better performance
The installation script will prompt you for an API key, or you can add it later to:
secrets/context7-key- Run the installer:
./install.sh(if you haven't already) - Try it out: Start OpenCode in any project with
opencode - Test Context7: Add
use context7to your prompts for up-to-date docs - Explore examples: Check the examples directory for common use cases
- Read guides: Browse the guides directory for detailed tutorials
- Configure IDE: Set up your preferred editor extensions for better integration
# Start OpenCode
opencode
# Try Context7 integration
"Create a Next.js middleware that checks for a valid JWT in cookies and redirects unauthenticated users to /login. use context7"
# Use custom commands
/summarize
# Get help
/helpThis repository includes custom commands and agents that can be synced to OpenCode:
# Sync local commands to OpenCode
./sync.sh
# Sync local agents to OpenCode
./sync-agents.sh
# Available commands will be listed after sync
# Use them with: /command-name
# Available agents will be listed after sync
# Use them with: @agent-name# Start OpenCode
opencode
# Use the summarize command
/summarize
# Use the ELI5 agent
@ELI5 How does machine learning work?
# Try Context7 integration
"Create a Next.js middleware that checks for a valid JWT in cookies and redirects unauthenticated users to /login. use context7"
# Get help
/helpIf you encounter issues:
- Check installation:
opencode --version - Verify config:
cat ~/.config/opencode/opencode.json - Test API key: Ensure
secrets/context7-keycontains your key (optional) - Reinstall: Run
./install.shagain
For more help, see:
- Report issues at: https://github.com/sst/opencode/issues
- Documentation: https://opencode.ai
- Community: Join our Discord server
We welcome contributions! Please see our contributing guidelines for more information.