What's inside OpenCode · V1
OpenCode v1.2.1 Internals
- architecture layers
- 4
- current binary
- 146 MB
- target after UPX
- 25–50 MB
- SDK namespaces
- 18
How OpenCode is built
Layer 1 — Binary wrapper
174-line entry shell
The thin wrapper that selects between OpenAPI SDK calls, local execution, and authentication. Sets the binary's working directory, environment, and signal handling.
Layer 2 — OpenAPI SDK
1,500+ TypeScript lines
Auto-generated SDK against the OpenCode public API. 18 namespaces (sessions, messages, files, snapshots, agents, etc.), 30+ typed event types for streaming.
Layer 3 — Provider routing
Anthropic + Ollama-cloud + OpenAI
Provider routing layer. Selects between native Anthropic, Ollama-cloud-routed models, and OpenAI based on configuration.
Layer 4 — Plugin host
Extension points
The plugin host that runs tool extensions. Three example enhanced-tool plugins shipped as research artifacts: search-files, format-code, api-test.
Binary size optimization path
146 MB is large. Most of the bulk is Go runtime + statically-linked dependencies. The research proposes a two-step compression path: (1) Build with stripped symbols and dead-code elimination via Go ldflags (-w -s -trimpath), expected ~30% reduction; (2) UPX compression on the stripped binary, expected ~50% additional reduction. Combined target: 25–50 MB final binary. This makes OpenCode practical to vendor inside container images and CI/CD pipelines where 146 MB is a problematic artifact size.
Three enhanced-tool plugins shipped as research artifacts
search-files
Project-wide regex search
Wraps ripgrep with project-aware ignores. Reports file:line matches plus context window.
format-code
Multi-language formatter
Routes through prettier, ruff, gofmt, rustfmt depending on file type. Single OpenCode tool invocation.
api-test
HTTP probe tool
Make GET/POST requests, assert status / JSON shape / latency from the agent. Useful for integration tests during agentic feature work.