What is OpenCode?
OpenCode is a specialized coding agent with:- File editing tools (read, edit, write, glob, grep)
- Git integration (commit, push, branch, PR creation)
- Code understanding (symbol search, imports, definitions)
- Multi-step workflows (refactoring, migrations, test generation)
Configuration
Enable OpenCode in youragent.toml:
agent.toml
Whether to use OpenCode for interactive coding workers (default: false)
Path to the
opencode binary. If not set, Spacebot checks PATH.Spawning OpenCode Workers
Whenopencode_enabled = true, interactive workers with coding-related tasks are routed to OpenCode:
refactor,migrate,update,edit,fiximplement,add,create(when referring to code)git,commit,branch,PR,pull request- File paths or code snippets in the task
OpenCode vs. Built-in Workers
- Built-in Worker
- OpenCode Worker
Tools:
shell,file,execbrowser,web_searchset_status,task_update
- Running tests
- Executing scripts
- System administration
- Web scraping
- One-shot file operations
Lifecycle
Spawn
Channel calls
spawn_worker with a coding task. Spacebot detects coding intent and spawns an OpenCode subprocess.Initialize
OpenCode receives the task and workspace directory. It loads project context (files, git state, recent changes).
Execute
OpenCode works through the task using its coding tools. It can read, edit, run tests, commit, etc.
Interact
The channel can send follow-up messages via the
route tool. OpenCode responds with progress updates or questions.Communication Protocol
Spacebot and OpenCode communicate via stdio (JSON-RPC-like messages):Message type:
task, message, status, result, errorMessage payload
Git Integration
OpenCode has built-in git awareness:- Auto-commit: Can commit changes with descriptive messages
- Branch management: Create, switch, merge branches
- PR creation: Use
gh pr createto open pull requests - Diff review: Show changes before committing
OpenCode respects
.gitignore and won’t commit secrets or build artifacts.Error Handling
If the OpenCode subprocess fails:- Crash: Spacebot detects the subprocess exit and marks the worker as failed
- Timeout: After the worker timeout, Spacebot kills the subprocess
- Parse error: Invalid JSON from OpenCode logs an error and continues
logs_dir/failed/ like built-in workers.
When to Use OpenCode
Use OpenCode
- Multi-file refactoring
- Code generation from specs
- Git workflows (branch, commit, PR)
- Complex search-and-replace
- Adding features across modules
Use Built-in Worker
- Running test suites
- Building/compiling
- System administration
- File copying/moving
- One-off script execution
Configuration Examples
Auto-detect OpenCode
Auto-detect OpenCode
Explicit Path
Explicit Path
Disabled (default)
Disabled (default)
Debugging
OpenCode worker logs include:- Subprocess spawn command
- Stdio communication (messages in/out)
- Exit code and stderr on failure
Limitations
Future Enhancements
Planned features:- Skill injection: Pass Spacebot skills to OpenCode for specialized workflows
- Shared memory: OpenCode can read Spacebot memories for project context
- Progress streaming: Real-time file edit notifications
- IDE integration: Connect OpenCode workers to VSCode/Cursor for live editing