Skip to content

Commit f0912ee

Browse files
committed
core: rename OPENCODE_PASSWORD to OPENCODE_SERVER_PASSWORD for clearer authentication configuration
1 parent 983f8ff commit f0912ee

6 files changed

Lines changed: 35 additions & 32 deletions

File tree

packages/opencode/src/cli/cmd/serve.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ export const ServeCommand = cmd({
88
builder: (yargs) => withNetworkOptions(yargs),
99
describe: "starts a headless opencode server",
1010
handler: async (args) => {
11-
if (!Flag.OPENCODE_PASSWORD) {
12-
console.log("Warning: OPENCODE_PASSWORD is not set; server is unsecured.")
11+
if (!Flag.OPENCODE_SERVER_PASSWORD) {
12+
console.log("Warning: OPENCODE_SERVER_PASSWORD is not set; server is unsecured.")
1313
}
1414
const opts = await resolveNetworkOptions(args)
1515
const server = Server.listen(opts)

packages/opencode/src/cli/cmd/web.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ export const WebCommand = cmd({
3333
builder: (yargs) => withNetworkOptions(yargs),
3434
describe: "start opencode server and open web interface",
3535
handler: async (args) => {
36-
if (!Flag.OPENCODE_PASSWORD) {
37-
UI.println(UI.Style.TEXT_WARNING_BOLD + "! " + "OPENCODE_PASSWORD is not set; server is unsecured.")
36+
if (!Flag.OPENCODE_SERVER_PASSWORD) {
37+
UI.println(UI.Style.TEXT_WARNING_BOLD + "! " + "OPENCODE_SERVER_PASSWORD is not set; server is unsecured.")
3838
}
3939
const opts = await resolveNetworkOptions(args)
4040
const server = Server.listen(opts)

packages/opencode/src/flag/flag.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ export namespace Flag {
2020
OPENCODE_DISABLE_CLAUDE_CODE || truthy("OPENCODE_DISABLE_CLAUDE_CODE_SKILLS")
2121
export const OPENCODE_FAKE_VCS = process.env["OPENCODE_FAKE_VCS"]
2222
export const OPENCODE_CLIENT = process.env["OPENCODE_CLIENT"] ?? "cli"
23-
export const OPENCODE_PASSWORD = process.env["OPENCODE_PASSWORD"]
23+
export const OPENCODE_SERVER_PASSWORD = process.env["OPENCODE_SERVER_PASSWORD"]
24+
export const OPENCODE_SERVER_USERNAME = process.env["OPENCODE_SERVER_USERNAME"]
2425

2526
// Experimental
2627
export const OPENCODE_EXPERIMENTAL = truthy("OPENCODE_EXPERIMENTAL")

packages/opencode/src/server/server.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,10 @@ export namespace Server {
9898
})
9999
})
100100
.use((c, next) => {
101-
const password = Flag.OPENCODE_PASSWORD
101+
const password = Flag.OPENCODE_SERVER_PASSWORD
102102
if (!password) return next()
103-
return basicAuth({ username: "opencode", password })(c, next)
103+
const username = Flag.OPENCODE_SERVER_USERNAME ?? "opencode"
104+
return basicAuth({ username, password })(c, next)
104105
})
105106
.use(async (c, next) => {
106107
const skipLogging = c.req.path === "/log"

packages/web/src/content/docs/cli.mdx

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ Start a headless OpenCode server for API access. Check out the [server docs](/do
358358
opencode serve
359359
```
360360

361-
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`).
361+
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`).
362362

363363
#### Flags
364364

@@ -454,7 +454,7 @@ Start a headless OpenCode server with a web interface.
454454
opencode web
455455
```
456456

457-
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`).
457+
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`).
458458

459459
#### Flags
460460

@@ -551,27 +551,28 @@ The opencode CLI takes the following global flags.
551551

552552
OpenCode can be configured using environment variables.
553553

554-
| Variable | Type | Description |
555-
| ------------------------------------- | ------- | ----------------------------------------------------- |
556-
| `OPENCODE_AUTO_SHARE` | boolean | Automatically share sessions |
557-
| `OPENCODE_GIT_BASH_PATH` | string | Path to Git Bash executable on Windows |
558-
| `OPENCODE_CONFIG` | string | Path to config file |
559-
| `OPENCODE_CONFIG_DIR` | string | Path to config directory |
560-
| `OPENCODE_CONFIG_CONTENT` | string | Inline json config content |
561-
| `OPENCODE_DISABLE_AUTOUPDATE` | boolean | Disable automatic update checks |
562-
| `OPENCODE_DISABLE_PRUNE` | boolean | Disable pruning of old data |
563-
| `OPENCODE_DISABLE_TERMINAL_TITLE` | boolean | Disable automatic terminal title updates |
564-
| `OPENCODE_PERMISSION` | string | Inlined json permissions config |
565-
| `OPENCODE_DISABLE_DEFAULT_PLUGINS` | boolean | Disable default plugins |
566-
| `OPENCODE_DISABLE_LSP_DOWNLOAD` | boolean | Disable automatic LSP server downloads |
567-
| `OPENCODE_ENABLE_EXPERIMENTAL_MODELS` | boolean | Enable experimental models |
568-
| `OPENCODE_DISABLE_AUTOCOMPACT` | boolean | Disable automatic context compaction |
569-
| `OPENCODE_DISABLE_CLAUDE_CODE` | boolean | Disable reading from `.claude` (prompt + skills) |
570-
| `OPENCODE_DISABLE_CLAUDE_CODE_PROMPT` | boolean | Disable reading `~/.claude/CLAUDE.md` |
571-
| `OPENCODE_DISABLE_CLAUDE_CODE_SKILLS` | boolean | Disable loading `.claude/skills` |
572-
| `OPENCODE_CLIENT` | string | Client identifier (defaults to `cli`) |
573-
| `OPENCODE_ENABLE_EXA` | boolean | Enable Exa web search tools |
574-
| `OPENCODE_PASSWORD` | string | Enable basic auth for `serve`/`web` (user `opencode`) |
554+
| Variable | Type | Description |
555+
| ------------------------------------- | ------- | ------------------------------------------------- |
556+
| `OPENCODE_AUTO_SHARE` | boolean | Automatically share sessions |
557+
| `OPENCODE_GIT_BASH_PATH` | string | Path to Git Bash executable on Windows |
558+
| `OPENCODE_CONFIG` | string | Path to config file |
559+
| `OPENCODE_CONFIG_DIR` | string | Path to config directory |
560+
| `OPENCODE_CONFIG_CONTENT` | string | Inline json config content |
561+
| `OPENCODE_DISABLE_AUTOUPDATE` | boolean | Disable automatic update checks |
562+
| `OPENCODE_DISABLE_PRUNE` | boolean | Disable pruning of old data |
563+
| `OPENCODE_DISABLE_TERMINAL_TITLE` | boolean | Disable automatic terminal title updates |
564+
| `OPENCODE_PERMISSION` | string | Inlined json permissions config |
565+
| `OPENCODE_DISABLE_DEFAULT_PLUGINS` | boolean | Disable default plugins |
566+
| `OPENCODE_DISABLE_LSP_DOWNLOAD` | boolean | Disable automatic LSP server downloads |
567+
| `OPENCODE_ENABLE_EXPERIMENTAL_MODELS` | boolean | Enable experimental models |
568+
| `OPENCODE_DISABLE_AUTOCOMPACT` | boolean | Disable automatic context compaction |
569+
| `OPENCODE_DISABLE_CLAUDE_CODE` | boolean | Disable reading from `.claude` (prompt + skills) |
570+
| `OPENCODE_DISABLE_CLAUDE_CODE_PROMPT` | boolean | Disable reading `~/.claude/CLAUDE.md` |
571+
| `OPENCODE_DISABLE_CLAUDE_CODE_SKILLS` | boolean | Disable loading `.claude/skills` |
572+
| `OPENCODE_CLIENT` | string | Client identifier (defaults to `cli`) |
573+
| `OPENCODE_ENABLE_EXA` | boolean | Enable Exa web search tools |
574+
| `OPENCODE_SERVER_PASSWORD` | string | Enable basic auth for `serve`/`web` |
575+
| `OPENCODE_SERVER_USERNAME` | string | Override basic auth username (default `opencode`) |
575576

576577
---
577578

packages/web/src/content/docs/server.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ opencode serve --cors http://localhost:5173 --cors https://app.example.com
3535

3636
### Authentication
3737

38-
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`.
38+
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`.
3939

4040
```bash
41-
OPENCODE_PASSWORD=your-password opencode serve
41+
OPENCODE_SERVER_PASSWORD=your-password opencode serve
4242
```
4343

4444
---

0 commit comments

Comments
 (0)