Prerequisites
Before starting, make sure you have:- Installed OpenCode - Follow the installation guide if you haven’t already
- Configured an API key - Set up at least one AI provider (see installation)
Start your first session
Navigate to your project
Open your terminal and navigate to any project directory where you want coding assistance:
Launch OpenCode
Start OpenCode by running:OpenCode will launch in full-screen mode with a beautiful TUI interface.
Select your AI model (optional)
Press
Ctrl+O to open the model selection dialog. You can choose from:- Anthropic: Claude 4 Sonnet, Claude 3.7 Sonnet, Claude 3.5 Haiku
- OpenAI: GPT-4.1, GPT-4o, O1, O3-mini, O4-mini
- Google: Gemini 2.5, Gemini 2.5 Flash
- GitHub Copilot: Multiple models including Claude and GPT
- Other providers: Groq, OpenRouter, Azure, Bedrock, VertexAI
OpenCode automatically selects the best available model based on your configured providers.
Start chatting
Press Press
i to focus the editor at the bottom of the screen. Type your question or request:Ctrl+S or Enter to send your message.Review AI actions
OpenCode’s AI will analyze your request and use tools to help:
- Read files with the
viewtool - Search code with the
grepandglobtools - Execute commands with the
bashtool - Modify files with the
editandwritetools
- Press
ato allow once - Press
Ato allow for session (all future requests) - Press
dto deny
Example conversations
Here are some example prompts to try:Understanding code
Understanding code
Making changes
Making changes
Debugging
Debugging
Git operations
Git operations
Essential keyboard shortcuts
OpenCode uses vim-like keybindings for navigation. Press
Ctrl+? anytime to see all shortcuts.Global shortcuts
| Shortcut | Action |
|---|---|
Ctrl+C | Quit application |
Ctrl+? | Toggle help dialog |
Ctrl+O | Select AI model |
Ctrl+K | Open command dialog |
Ctrl+A | Switch session |
Ctrl+N | Create new session |
Ctrl+X | Cancel current AI operation |
Esc | Close dialog or exit mode |
Editor shortcuts
| Shortcut | Action |
|---|---|
i | Focus editor (from message view) |
Ctrl+S or Enter | Send message |
Ctrl+E | Open external editor (e.g., $EDITOR) |
Esc | Blur editor and return to messages |
Navigation
| Shortcut | Action |
|---|---|
↑ or k | Move up |
↓ or j | Move down |
← or h | Move left |
→ or l | Move right |
Working with sessions
OpenCode automatically saves your conversations in sessions stored in a SQLite database at~/.opencode/db.sqlite.
Switch sessions
- Press
Ctrl+Ato open the session switcher - Navigate with
↑/↓orj/k - Press
Enterto load a session
Auto-compact feature
When your conversation gets long (approaching the model’s context limit), OpenCode can automatically summarize it:- Enabled by default
- Triggers at 95% of context window
- Creates a new session with the summary
- Prevents “out of context” errors
Using custom commands
Custom commands let you create reusable prompts. PressCtrl+K to open the command dialog and explore:
- Initialize Project: Creates/updates project memory file
- Compact Session: Manually trigger conversation summarization
- User commands: Your custom commands from
~/.config/opencode/commands/ - Project commands: Project-specific commands from
.opencode/commands/
Create your first custom command
Non-interactive mode
For scripting and automation, use OpenCode in non-interactive mode:Advanced options
Working directory
Start OpenCode in a specific directory:Debug mode
Enable debug logging to troubleshoot issues:Ctrl+L.
Configuration file locations
OpenCode looks for configuration in these locations (in order):./.opencode.json- Project-specific config (highest priority)$XDG_CONFIG_HOME/opencode/.opencode.json- User config$HOME/.opencode.json- User config (fallback)
Tips for effective use
Be specific with requests
Be specific with requests
Instead of “fix this”, say “fix the nil pointer error in processRequest on line 45”
Let AI explore first
Let AI explore first
For new codebases, start with “explore this codebase and tell me what it does” before making changes
Review tool usage
Review tool usage
Pay attention to which tools the AI uses - this helps you understand what it’s doing
Use sessions effectively
Use sessions effectively
Create a new session (
Ctrl+N) for unrelated tasks to maintain clear contextLeverage git integration
Leverage git integration
Ask AI to “create a commit” or “create a PR” - it follows best practices automatically
Troubleshooting
”No API key found”
Make sure you’ve set an environment variable or config file with your API key:“Command not found: opencode”
Ensure OpenCode’s install directory is in your PATH:Permission denied errors
Check file permissions if you see permission errors:Next steps
Now that you’re familiar with the basics:Configuration guide
Learn about LSP integration, MCP servers, shell config, and more
Custom commands
Create powerful custom commands with named arguments
AI tools reference
Understand all tools available to the AI assistant
Keyboard shortcuts
Master all keyboard shortcuts for maximum efficiency