The open source coding agent.
TypeScript
core: rename OPENCODE_PASSWORD to OPENCODE_SERVER_PASSWORD for clearer authentication configuration
Dax Raadf0912ee838e7
diff --git a/packages/opencode/src/cli/cmd/serve.ts b/packages/opencode/src/cli/cmd/serve.tsindex 441240609f2..bee2c8f711f 100644--- a/packages/opencode/src/cli/cmd/serve.ts+++ b/packages/opencode/src/cli/cmd/serve.ts@@ -8,8 +8,8 @@ export const ServeCommand = cmd({builder: (yargs) => withNetworkOptions(yargs),describe: "starts a headless opencode server",handler: async (args) => {- if (!Flag.OPENCODE_PASSWORD) {- console.log("Warning: OPENCODE_PASSWORD is not set; server is unsecured.")+ if (!Flag.OPENCODE_SERVER_PASSWORD) {+ console.log("Warning: OPENCODE_SERVER_PASSWORD is not set; server is unsecured.")}const opts = await resolveNetworkOptions(args)const server = Server.listen(opts)diff --git a/packages/opencode/src/cli/cmd/web.ts b/packages/opencode/src/cli/cmd/web.tsindex abb34779898..2c207ecc2f2 100644--- a/packages/opencode/src/cli/cmd/web.ts+++ b/packages/opencode/src/cli/cmd/web.ts@@ -33,8 +33,8 @@ export const WebCommand = cmd({builder: (yargs) => withNetworkOptions(yargs),describe: "start opencode server and open web interface",handler: async (args) => {- if (!Flag.OPENCODE_PASSWORD) {- UI.println(UI.Style.TEXT_WARNING_BOLD + "! " + "OPENCODE_PASSWORD is not set; server is unsecured.")+ if (!Flag.OPENCODE_SERVER_PASSWORD) {+ UI.println(UI.Style.TEXT_WARNING_BOLD + "! " + "OPENCODE_SERVER_PASSWORD is not set; server is unsecured.")}const opts = await resolveNetworkOptions(args)const server = Server.listen(opts)diff --git a/packages/opencode/src/flag/flag.ts b/packages/opencode/src/flag/flag.tsindex 77260a84cf2..ad6052dec14 100644--- a/packages/opencode/src/flag/flag.ts+++ b/packages/opencode/src/flag/flag.ts@@ -20,7 +20,8 @@ export namespace Flag {OPENCODE_DISABLE_CLAUDE_CODE || truthy("OPENCODE_DISABLE_CLAUDE_CODE_SKILLS")export const OPENCODE_FAKE_VCS = process.env["OPENCODE_FAKE_VCS"]export const OPENCODE_CLIENT = process.env["OPENCODE_CLIENT"] ?? "cli"- export const OPENCODE_PASSWORD = process.env["OPENCODE_PASSWORD"]+ export const OPENCODE_SERVER_PASSWORD = process.env["OPENCODE_SERVER_PASSWORD"]+ export const OPENCODE_SERVER_USERNAME = process.env["OPENCODE_SERVER_USERNAME"]// Experimentalexport const OPENCODE_EXPERIMENTAL = truthy("OPENCODE_EXPERIMENTAL")diff --git a/packages/opencode/src/server/server.ts b/packages/opencode/src/server/server.tsindex e79c68558f6..52457515b8e 100644--- a/packages/opencode/src/server/server.ts+++ b/packages/opencode/src/server/server.ts@@ -98,9 +98,10 @@ export namespace Server {})}).use((c, next) => {- const password = Flag.OPENCODE_PASSWORD+ const password = Flag.OPENCODE_SERVER_PASSWORDif (!password) return next()- return basicAuth({ username: "opencode", password })(c, next)+ const username = Flag.OPENCODE_SERVER_USERNAME ?? "opencode"+ return basicAuth({ username, password })(c, next)}).use(async (c, next) => {const skipLogging = c.req.path === "/log"diff --git a/packages/web/src/content/docs/cli.mdx b/packages/web/src/content/docs/cli.mdxindex 11a1d60d1ee..d1d11ed70d9 100644--- a/packages/web/src/content/docs/cli.mdx+++ b/packages/web/src/content/docs/cli.mdx@@ -358,7 +358,7 @@ Start a headless OpenCode server for API access. Check out the [server docs](/doopencode serve```-This starts an HTTP server that provides API access to opencode functionality without the TUI interface. Set `OPENCODE_PASSWORD` to enable HTTP basic auth (username `opencode`).+This starts an HTTP server that provides API access to opencode functionality without the TUI interface. Set `OPENCODE_SERVER_PASSWORD` to enable HTTP basic auth (username defaults to `opencode`).#### Flags@@ -454,7 +454,7 @@ Start a headless OpenCode server with a web interface.opencode web```-This starts an HTTP server and opens a web browser to access OpenCode through a web interface. Set `OPENCODE_PASSWORD` to enable HTTP basic auth (username `opencode`).+This starts an HTTP server and opens a web browser to access OpenCode through a web interface. Set `OPENCODE_SERVER_PASSWORD` to enable HTTP basic auth (username defaults to `opencode`).#### Flags@@ -551,27 +551,28 @@ The opencode CLI takes the following global flags.OpenCode can be configured using environment variables.-| Variable | Type | Description |-| ------------------------------------- | ------- | ----------------------------------------------------- |-| `OPENCODE_AUTO_SHARE` | boolean | Automatically share sessions |-| `OPENCODE_GIT_BASH_PATH` | string | Path to Git Bash executable on Windows |-| `OPENCODE_CONFIG` | string | Path to config file |-| `OPENCODE_CONFIG_DIR` | string | Path to config directory |-| `OPENCODE_CONFIG_CONTENT` | string | Inline json config content |-| `OPENCODE_DISABLE_AUTOUPDATE` | boolean | Disable automatic update checks |-| `OPENCODE_DISABLE_PRUNE` | boolean | Disable pruning of old data |-| `OPENCODE_DISABLE_TERMINAL_TITLE` | boolean | Disable automatic terminal title updates |-| `OPENCODE_PERMISSION` | string | Inlined json permissions config |-| `OPENCODE_DISABLE_DEFAULT_PLUGINS` | boolean | Disable default plugins |-| `OPENCODE_DISABLE_LSP_DOWNLOAD` | boolean | Disable automatic LSP server downloads |-| `OPENCODE_ENABLE_EXPERIMENTAL_MODELS` | boolean | Enable experimental models |-| `OPENCODE_DISABLE_AUTOCOMPACT` | boolean | Disable automatic context compaction |-| `OPENCODE_DISABLE_CLAUDE_CODE` | boolean | Disable reading from `.claude` (prompt + skills) |-| `OPENCODE_DISABLE_CLAUDE_CODE_PROMPT` | boolean | Disable reading `~/.claude/CLAUDE.md` |-| `OPENCODE_DISABLE_CLAUDE_CODE_SKILLS` | boolean | Disable loading `.claude/skills` |-| `OPENCODE_CLIENT` | string | Client identifier (defaults to `cli`) |-| `OPENCODE_ENABLE_EXA` | boolean | Enable Exa web search tools |-| `OPENCODE_PASSWORD` | string | Enable basic auth for `serve`/`web` (user `opencode`) |+| Variable | Type | Description |+| ------------------------------------- | ------- | ------------------------------------------------- |+| `OPENCODE_AUTO_SHARE` | boolean | Automatically share sessions |+| `OPENCODE_GIT_BASH_PATH` | string | Path to Git Bash executable on Windows |+| `OPENCODE_CONFIG` | string | Path to config file |+| `OPENCODE_CONFIG_DIR` | string | Path to config directory |+| `OPENCODE_CONFIG_CONTENT` | string | Inline json config content |+| `OPENCODE_DISABLE_AUTOUPDATE` | boolean | Disable automatic update checks |+| `OPENCODE_DISABLE_PRUNE` | boolean | Disable pruning of old data |+| `OPENCODE_DISABLE_TERMINAL_TITLE` | boolean | Disable automatic terminal title updates |+| `OPENCODE_PERMISSION` | string | Inlined json permissions config |+| `OPENCODE_DISABLE_DEFAULT_PLUGINS` | boolean | Disable default plugins |+| `OPENCODE_DISABLE_LSP_DOWNLOAD` | boolean | Disable automatic LSP server downloads |+| `OPENCODE_ENABLE_EXPERIMENTAL_MODELS` | boolean | Enable experimental models |+| `OPENCODE_DISABLE_AUTOCOMPACT` | boolean | Disable automatic context compaction |+| `OPENCODE_DISABLE_CLAUDE_CODE` | boolean | Disable reading from `.claude` (prompt + skills) |+| `OPENCODE_DISABLE_CLAUDE_CODE_PROMPT` | boolean | Disable reading `~/.claude/CLAUDE.md` |+| `OPENCODE_DISABLE_CLAUDE_CODE_SKILLS` | boolean | Disable loading `.claude/skills` |+| `OPENCODE_CLIENT` | string | Client identifier (defaults to `cli`) |+| `OPENCODE_ENABLE_EXA` | boolean | Enable Exa web search tools |+| `OPENCODE_SERVER_PASSWORD` | string | Enable basic auth for `serve`/`web` |+| `OPENCODE_SERVER_USERNAME` | string | Override basic auth username (default `opencode`) |---diff --git a/packages/web/src/content/docs/server.mdx b/packages/web/src/content/docs/server.mdxindex a123acb1504..7229e09b22f 100644--- a/packages/web/src/content/docs/server.mdx+++ b/packages/web/src/content/docs/server.mdx@@ -35,10 +35,10 @@ opencode serve --cors http://localhost:5173 --cors https://app.example.com### Authentication-Set `OPENCODE_PASSWORD` to protect the server with HTTP basic auth. The username is always `opencode`, and the password is the value of `OPENCODE_PASSWORD`. This applies to both `opencode serve` and `opencode web`.+Set `OPENCODE_SERVER_PASSWORD` to protect the server with HTTP basic auth. The username defaults to `opencode`, or set `OPENCODE_SERVER_USERNAME` to override it. This applies to both `opencode serve` and `opencode web`.```bash-OPENCODE_PASSWORD=your-password opencode serve+OPENCODE_SERVER_PASSWORD=your-password opencode serve```---