IDE Integration
opencode integrates with your editor and IDE through several mechanisms -- from the $EDITOR environment variable for prompt composition, to LSP for code intelligence, to plugins for deeper integration.
Editor Fundamentals
The $EDITOR Environment Variable
Many opencode features rely on the EDITOR environment variable:
/editorcommand -- opens your current message in $EDITOR for composing complex prompts/exportcommand -- opens the session transcript in $EDITOR for saving
Set EDITOR in your shell profile:
export EDITOR="code --wait" # VS Code
export EDITOR="cursor --wait" # Cursor
export EDITOR="windsurf --wait" # Windsurf
export EDITOR="nvim" # Neovim
export EDITOR="vim" # Vim
export EDITOR="nano" # Nano
export EDITOR="subl -n -w" # Sublime Text
The --wait Flag for GUI Editors
GUI editors (VS Code, Cursor, Windsurf, Sublime Text) require the --wait flag. This makes the editor block the terminal until the file tab is closed, ensuring opencode waits for you to finish editing.
Without --wait, the editor spawns a process and returns immediately, causing opencode to send an empty or incomplete prompt.
Terminal Editors
Terminal-based editors work without the --wait flag because they run in the foreground by nature:
- Neovim (
nvim) -- modern Vim fork with LSP support - Vim (
vim) -- classic modal editor - Nano (
nano) -- simple, beginner-friendly editor - Helix (
hx) -- modern modal editor with built-in LSP - Kakoune (
kak) -- modal editor with multiple selections - Emacs (
emacs -nw) -- terminal Emacs (non-windowed) - Micro (
micro) -- modern terminal editor with familiar keybinds
VS Code
CLI Workflow
Use VS Code as your $EDITOR:
export EDITOR="code --wait"
Now when you run /editor in opencode's TUI, VS Code opens with your prompt text. Write your prompt, save the file, close the tab, and opencode sends the content.
Inline Code Assistance
While working in VS Code, you can:
- Keep opencode running in a split terminal (Ctrl+`)
- Use
@file references to bring editor files into context - Use
!commands to run VS Code terminal tasks - View diffs from opencode's changes in VS Code's source control panel
VS Code Extension
The opencode VS Code extension provides deeper integration:
- Chat panel within VS Code
- Inline code suggestions
- File-level operations from the editor context menu
- Direct access to opencode commands
Install it from the VS Code Marketplace.
Cursor
Cursor is an AI-first IDE built on VS Code. Use it with opencode:
export EDITOR="cursor --wait"
Cursor's AI features and opencode can complement each other:
- Use Cursor's inline editing for quick changes
- Use opencode for complex, multi-file tasks
- Reference Cursor's AI output in opencode conversations
Windsurf
Windsurf is another AI-native IDE. Integration:
export EDITOR="windsurf --wait"
Neovim
Neovim integrates naturally with opencode since both run in the terminal.
Basic Setup
export EDITOR="nvim"
Split Layout
Run opencode and Neovim side by side using tmux:
# In tmux
tmux split-window -h
# Left pane: nvim
# Right pane: opencode
Neovim Plugin
For deeper integration, consider using the opencode Neovim plugin (if available) or the generic plugin system described below.
Tmux Integration
tmux pairs exceptionally well with opencode:
# Create a session with opencode
tmux new-session -s opencode 'opencode'
# Split vertically for editor
tmux split-window -h 'nvim'
# Create a dedicated window for shell commands
tmux new-window 'bash'
Attach opencode to specific tmux panes for ! command execution:
{
"tools": {
"bash": {
"tmux": {
"session": "opencode",
"window": "shell",
"pane": 0
}
}
}
}
LSP Integration
opencode uses Language Server Protocol (LSP) for code intelligence when the lsp tool is available to agents.
Supported Features
- Go to definition -- find where a symbol is defined
- Find references -- locate all usages of a symbol
- Hover information -- type signatures, documentation
- Diagnostics -- errors, warnings, hints from the language server
- Code completion -- context-aware completion suggestions
- Code actions -- quick fixes, refactoring suggestions
Configure LSP Servers
opencode can leverage language servers you already have installed. Configure them in your opencode config:
{
"lsp": {
"typescript": {
"command": "typescript-language-server",
"args": ["--stdio"]
},
"rust": {
"command": "rust-analyzer"
},
"python": {
"command": "pyright-langserver",
"args": ["--stdio"]
},
"go": {
"command": "gopls"
},
"java": {
"command": "jdtls"
},
"lua": {
"command": "lua-language-server"
}
}
}
How Agents Use LSP
When you ask a question like "Find all usages of the authenticate function and refactor it", the agent can:
- Use
globto locate relevant files - Use
lspto find all references toauthenticate - Use
grepto examine each reference - Use
readto understand the context - Use
editto apply the refactoring
This workflow is significantly more accurate than text-based search alone.
Install Language Servers
Common language servers:
# TypeScript / JavaScript
npm install -g typescript-language-server
# Python
npm install -g pyright
# Rust (bundled with Rust toolchain)
rustup component add rust-analyzer
# Go
go install golang.org/x/tools/gopls@latest
# Lua
npm install -g lua-language-server
# Java
# Download from https://download.eclipse.org/jdtls/
# JSON
npm install -g vscode-langservers-extracted
# YAML
npm install -g yaml-language-server
Plugin System
The plugin system allows deeper integration with editors and tools:
opencode plugin <module>
Available plugins may include:
- Editor-specific plugins (VS Code, Neovim, JetBrains)
- File watchers
- Custom tool providers
- Protocol adapters (MCP, ACP)
Creating a Plugin
Plugins are Node.js modules that implement the opencode plugin interface:
module.exports = {
name: 'my-editor-plugin',
version: '1.0.0',
activate(context) {
// Register commands, tools, or hooks
context.registerCommand('editor.openFile', (filePath) => {
// Open file in the editor
});
},
deactivate() {
// Cleanup
}
};
Best Practices
Keep opencode Visible
Run opencode in a dedicated terminal pane or window so you can see agent output while editing.
Use @ References from Your Editor
When you see a file path in your editor, reference it in opencode with @:
I'm working on @src/components/LoginForm.tsx. Add form validation.
Iterate Between Editor and Agent
Effective workflow:
- Ask opencode to make a change
- Review the diff in opencode's output
- Open the changed file in your editor (
/editoror manually) - Make manual adjustments
- Iterate -- ask for refinements
Use Git Integration
Since opencode creates git snapshots, you can use your editor's git blame, diff, and history features alongside opencode:
# In editor terminal
git diff # See opencode's changes
git log --oneline # See snapshot history
Set Up Keyboard Shortcuts
Create OS-level or terminal-level shortcuts to quickly switch focus between your editor and opencode.
tmux Keybinding Example
# ~/.tmux.conf
bind-key -n M-o send-keys "opencode run --attach http://localhost:4096" C-m
bind-key -n M-p send-keys "opencode run --attach http://localhost:4096 \"$(pbpaste)\"" C-m
What's Next
- Terminal UI -- TUI commands and keybinds
- CLI Usage -- Non-interactive mode and scripting
- Integrations -- MCP, LSP, GitHub, GitLab
- Configuration -- LSP and plugin configuration