| type | Project | |||
|---|---|---|---|---|
| description | OpenCodeRust の概要、使い方、workspace 構成への入口。 | |||
| tags |
|
A Rust implementation of OpenCode
OpenCodeRust is the Rust implementation and evolution of OpenCode. It provides a full CLI/TUI/Server workflow for local AI coding agents, session management, tool invocation, MCP/LSP integration, and plugin extensions.
- Project name:
OpenCodeRust - Executable:
opencoderust
- Interaction modes: TUI (default), CLI single run, HTTP server, Web/ACP mode
- Sessions: Create, continue, fork sessions; import/export
- Tool system: Built-in read/write/edit, shell, patch, and related tools
- Model support: Multiple providers, agent mode switching
- Extensibility: Plugin bridge (including TS plugins), MCP, LSP
- Terminal: Improved layout, collapsible sidebar, syntax highlighting, path completion
- Rust 1.97 or later (MSRV declared as
rust-versionin the workspace rootCargo.toml) - Cargo
- C compiler and build tools (
gccandmake; alsopkg-configwhen linking against a system SQLite instead of the bundled build) - Git (recommended)
sqlite3CLI (external dependency of thedbcommand and the backup/restore procedures indocs/opencode-storage.md)- GitHub CLI (
gh) (external dependency of thegithubandprcommands)
cargo build -p opencode-cliTo ensure you are running this project's binary, run from the repo root:
./target/debug/opencoderustaftercargo build -p opencode-clicargo run -p opencode-cli --to always use this repo's version
./target/debug/opencoderust --helpor
cargo run -p opencode-cli -- --help- Default: start TUI:
cargo run -p opencode-cli --- Start TUI explicitly:
cargo run -p opencode-cli -- tui- Single non-interactive run:
cargo run -p opencode-cli -- run "Check this repo for risks"- Start HTTP server:
cargo run -p opencode-cli -- serve --port 3000 --hostname 127.0.0.1From the repo root use ./target/debug/opencoderust or
cargo run -p opencode-cli --. These commands match the current
./target/debug/opencoderust --help:
tui– Start interactive terminal UIattach– Attach to a running serverrun– Run a single messageserve– Start HTTP serverweb– Start headless server and open web UIacp– Start ACP servermodels– List available modelssession– Session managementstats– Token/cost statisticsdb– Database toolsconfig– Show configurationauth– Credential managementagent– Agent managementdebug– Debugging and troubleshootingmcp– MCP managementexport/import– Export/import sessionsgithub/pr– GitHub-related featuresupgrade/uninstall– Upgrade and uninstallgenerate– Generate OpenAPI specversion– Show version
Subcommand help:
./target/debug/opencoderust tui --help
./target/debug/opencoderust run --help
./target/debug/opencoderust serve --help
./target/debug/opencoderust session --helpThe TUI does not support text entry through an IME (input method editor).
To enter Japanese or other non-ASCII text, copy it to the clipboard first
and paste it into the prompt with Ctrl+V.
Ctrl+X is a leader key: press it, then one of n / l / m / a /
t / b / s / q / u / r. The prompt status line lists the
available keys while it waits for the next key. Press Esc to cancel.
Configuration sources are merged in the following order, from lowest to highest precedence. Each later source overrides earlier ones; the managed source is merged last and therefore has the highest priority.
| Order | Source | Details |
|---|---|---|
| 1 (lowest) | Remote well-known | .well-known/opencode org defaults |
| 2 | Global | ~/.config/opencode/opencode.json{,c} |
| 3 | Custom | Path from OPENCODE_CONFIG |
| 4 | Project | opencode.json{,c} found by upward search (see note) |
| 5 | .opencode dirs |
Agents, commands, plugins, modes (markdown) |
| 6 | Inline | OPENCODE_CONFIG_CONTENT |
| 7 | Env overrides | OPENCODE_PERMISSION, OPENCODE_DISABLE_* |
| 8 (highest) | Managed | Enterprise config directory, merged last |
At each project level both opencode.jsonc and opencode.json are searched.
The project layer also reads $HOME/.opencode/opencode.json{,c} and
$OPENCODE_CONFIG_DIR/opencode.json{,c} explicitly.
.opencode/opencode.json{,c} are read by the project find-up scan, so the
.opencode directory scan itself only loads agents, commands, plugins and
modes from markdown/JS files. Environment overrides are applied before the
managed config so that managed stays the highest-priority source.
Relative file references ({file:...}) in the inline source
(OPENCODE_CONFIG_CONTENT) resolve against the process current working
directory, not the parent directory of the OPENCODE_CONFIG file.
See: docs/opencode-config.md
Runtime changes through PATCH /config take effect immediately for most keys.
logLevel / log_level and server.* bind keys are read only at startup and
require a restart, as do the environment variables listed in
Logging.
If persistence to disk fails, the response includes persisted: false; the
in-memory change still applies until restart but will be lost on the next start.
Successful responses keep the existing shape without a persisted key.
Run opencoderust config --check to validate the current configuration. It
prints Configuration is valid on success and exits non-zero on errors.
Most configuration problems produce a warning and startup continues instead of failing. Review each warning as follows.
- Unknown keys (top level or nested): a warning is logged and startup continues. User-defined names are masked with an asterisk. Check the warned key path and remove or rename the misspelled key.
- Wrong value types: only the field path is warned, never the value. Check that field's type in the config reference and correct the value.
- Undefined
{env:VAR}placeholders: expanded to an empty string with a warning (this is not fail-closed). Confirm the variable is set in the environment, or replace the placeholder with a literal value. - Deprecated keys
mode,tools,autoshare: accepted with a migration warning. Move to the current equivalent key and drop the old one. - Explicit
OPENCODE_CONFIGpath missing: a warning names the file only. Create the file or point the variable at an existing config file. - MCP disk sync failure: an
x-mcp-sync-warningheader and a fixed warning are emitted. Check disk space and write permissions for the MCP state directory, then retry. logLevel/log_level,server.*bind keys, and environment variables: read only at startup. Restart the process after changing them.
- Log level resolution: config
log_level(when set) ->RUST_LOG->info. UseRUST_LOG(for exampleRUST_LOG=debug) to raise verbosity without editing config files. - TUI sessions write logs to a file. Non-TUI commands (
run,serve, and other subcommands) print to stdout/stderr and do not create a log file. Exception:run --format jsoncreates a file log so stdout stays a clean JSON Lines stream. - Default log directory (Unix):
$XDG_STATE_HOME/opencode/logs, or$HOME/.local/state/opencode/logswhenXDG_STATE_HOMEis unset. IfHOMEis unavailable too,./.opencode/logsis used. Each launch writes a<YYYY-MM-DDTHHMMSS>-<pid>-<nanoseconds>.logfile; the suffix prevents truncation when two processes start in the same second. - Seven generations (the current file plus six previous ones) are kept by
modification time. Override with
OPENCODE_LOG_RETENTION(positive integer; invalid or zero falls back to 7). - Log files are created with mode
0600; pre-existing files with looser permissions are corrected to0600on open. If a log file cannot be opened, events fall back to stderr instead of being silently dropped. - If a log file is missing or unreadable, check the directory above (or the
path reported at startup) and set
XDG_STATE_HOMEexplicitly to redirect logs to a known location. Buffered entries are flushed when the process exits normally.
PATCH /config applies most settings immediately, but some keys are read only
at startup. A successful PATCH response lists them under restart_required:
| Setting | PATCH /config |
Restart needed |
|---|---|---|
| Providers, models, permissions, and other runtime keys | Immediate | No |
server.* bind keys (port, hostname, cors, mdns) |
Not applied | Yes |
logLevel / log_level |
Not applied | Yes |
| Environment variables (see note) | Not a PATCH key | N/A |
Environment variables are not configuration keys, so they never appear in
restart_required. The following are resolved once when the process starts;
changing them while it runs has no effect and requires a restart:
RUST_LOG– log level filter (resolution order: configlog_level, thenRUST_LOG, theninfo)OPENCODE_LOG_RETENTION– number of log generations to keepOPENCODE_NO_AUTH– whether authentication is disabledOPENCODE_CONFIG_STRICT_ENV–true/1/yes(case-insensitive) makes an undefined{env:VAR}fail loading, including chained references insideconfig.envvalues (even unused ones). Default warns and continues.OPENCODE_AUTO_SHARE–true/1/yes(case-insensitive) triggers auto-sharing forrun --attach, right after the session is created (before the first message);onis false. No effect on localrun. Same asconfig.share: auto.OPENCODE_DATA_DIR– base directory for the database and other local data
logLevel / log_level and server.* bind keys are likewise read only at
startup, as shown in the table above.
Two probes are exposed. Both /health and /global/health return the same
JSON schema:
{"status":"ok","version":"<version>","healthy":true}The existing status and version fields are kept for compatibility; the
healthy field mirrors status == "ok" and was previously only present on
/global/health. Liveness probes are deliberately exempt from the
authentication middleware so the CLI and TUI can wait for startup without a
token. Readiness probes and all other routes still require the startup Bearer
token when authentication is enabled.
GET /health (aliases: GET /health/live, GET /global/health) is a pure
liveness probe. It always returns 200 with status: "ok" while the process
can serve HTTP; it does not inspect the database. These three paths match
exactly (query strings are ignored), and none of them requires an
Authorization header. Only these three root paths are exempt; the /api
aliases (for example /api/health) still require authentication, so use the
root paths for unauthenticated probes. The CLI and TUI use /health without a
token to wait for a local server to start:
curl -fsS http://127.0.0.1:3000/healthUse liveness only to decide whether to restart a process. Never use it as a traffic or dependency gate.
GET /health/ready (alias: GET /global/ready) probes the database with a
lightweight SELECT 1 through the configured repository. It returns:
200withstatus: "ok"when the database is reachable and usable.503withstatus: "error"andhealthy: falsewhen the repository is not initialized, the connection is closed, the database is locked or the stored data is corrupt.
Database migrations are applied at startup. The probe only checks connectivity
and basic usability with SELECT 1; it does not verify migration status.
curl -fsS -o /dev/null -w '%{http_code}\n' \
http://127.0.0.1:3000/health/readyUnlike liveness, /health/ready and /global/ready pass through the
authentication middleware. Send Authorization: Bearer <token> when
authentication is enabled. Point load-balancer and orchestrator readiness gates
at /health/ready, not at /health. A static 200 from /health no longer
routes traffic to a server whose database is unavailable.
Replace the host and port with the values passed to serve --hostname and
--port.
- Authentication is enabled by default. A random Bearer token (32 bytes,
URL-safe base64) is generated at startup; send it on every request as
Authorization: Bearer <token>, except for the liveness probes documented above. The token value is masked in logs, and the startup notice on stderr reports whether authentication is enabled. - The token is regenerated on every restart. Clients must refresh the
Authorizationheader after restarting the server. OPENCODE_NO_AUTHdisables authentication only when set totrue,1, oryes(case-insensitive, trimmed). Any other value, including unset, keeps authentication enabled (fail-closed). Do not disable it outside local development.
The complete 21-crate map and major execution paths are documented in
docs/architecture.md.
crates/opencode-cli– CLI entrypoint (binary:opencoderust)crates/opencode-server– HTTP/SSE/WebSocket servercrates/opencode-tui– Terminal UIcrates/opencode-session– Sessions and messagescrates/opencode-tool– Tool registration and executioncrates/opencode-provider– Model provider adapterscrates/opencode-plugin– Plugin system and subprocess bridgecrates/opencode-mcp– MCP client and registrationcrates/opencode-lsp– LSP supportcrates/opencode-storage– SQLite storage
CI is defined in .github/workflows/ci.yml and delegated to the shared
Seduce0068/workflows/.github/workflows/rust-gates.yml@v1 workflow.
Cargo.lock is committed, so cargo commands use --locked; a cargo audit
gate is also enabled. The four extra_gates below mirror the CI job exactly.
cargo check --workspace --all-features --all-targets --locked
cargo test --workspace --all-features --all-targets --locked
cargo clippy --workspace --all-features --all-targets --locked -- \
-D warnings -D clippy::undocumented_unsafe_blocks
cargo build --workspace --release --lockedThe default-feature gates (fmt / check / test / clippy) also run with
locked: true, audit: true, and
clippy_args: -D clippy::undocumented_unsafe_blocks, so -D warnings and
the unsafe-block lint apply to both feature sets.
cargo nextest run --workspace remains available as a faster local test
runner; CI uses cargo test (see the gates above).
Minimal check (typical):
cargo check -p opencode-cli
cargo check -p opencode-tui- Project architecture:
docs/architecture.md - User guide:
USER_GUIDE.md - Docs index:
docs/README.md - CLI:
docs/opencode-cli.md - TUI:
docs/opencode-tui.md - Server:
docs/opencode-server.md - Tools:
docs/opencode-tool.md - Provider:
docs/opencode-provider.md - Config:
docs/opencode-config.md - Storage and backups:
docs/opencode-storage.md
- The executable name is
opencoderust. OpenCodeRust is the project name.