Skip to content

Commit b6baeb7

Browse files
committed
feat: add OPENCODE_APPNAME for profile isolation
Adds OPENCODE_APPNAME environment variable to enable easy profile isolation for managing multiple identities (e.g., work and personal) with separate OAuth credentials, settings, and history. When set, OPENCODE_APPNAME replaces 'opencode' as the app name in XDG path construction, creating isolated directories for data, cache, config, and state. Path precedence: - Explicit overrides (OPENCODE_*_DIR) take highest priority - OPENCODE_APPNAME-derived paths come next - Default 'opencode' as fallback Example usage: OPENCODE_APPNAME=opencode-work opencode OPENCODE_APPNAME=opencode-personal opencode Ref anomalyco#8968
1 parent 9e191d6 commit b6baeb7

4 files changed

Lines changed: 46 additions & 1 deletion

File tree

‎packages/opencode/src/flag/flag.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export namespace Flag {
1919
export declare const OPENCODE_CONFIG_DIR: string | undefined
2020
export declare const OPENCODE_PLUGIN_META_FILE: string | undefined
2121
export const OPENCODE_CONFIG_CONTENT = process.env["OPENCODE_CONFIG_CONTENT"]
22+
export const OPENCODE_APPNAME = process.env["OPENCODE_APPNAME"]
2223
export const OPENCODE_DATA_DIR = process.env["OPENCODE_DATA_DIR"]
2324
export const OPENCODE_CACHE_DIR = process.env["OPENCODE_CACHE_DIR"]
2425
export const OPENCODE_LOG_DIR = process.env["OPENCODE_LOG_DIR"]

‎packages/opencode/src/global/index.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@ import os from "os"
55
import { Flag } from "../flag/flag"
66
import { Filesystem } from "../util/filesystem"
77

8-
const app = "opencode"
8+
// Path precedence:
9+
// 1. Explicit path overrides (OPENCODE_*_DIR) take highest priority
10+
// 2. OPENCODE_APPNAME-derived paths (e.g., ~/.local/share/opencode-work)
11+
// 3. Default XDG paths with "opencode" as app name
12+
//
13+
// Example: Profile isolation for separate OAuth identities
14+
// OPENCODE_APPNAME=opencode-work opencode # Work profile
15+
// OPENCODE_APPNAME=opencode-personal opencode # Personal profile
16+
const app = Flag.OPENCODE_APPNAME || "opencode"
917

1018
const data = Flag.OPENCODE_DATA_DIR || path.join(xdgData!, app)
1119
const cache = Flag.OPENCODE_CACHE_DIR || path.join(xdgCache!, app)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ OpenCode can be configured using environment variables.
561561
| `OPENCODE_TUI_CONFIG` | string | Path to TUI config file |
562562
| `OPENCODE_CONFIG_DIR` | string | Path to config directory |
563563
| `OPENCODE_CONFIG_CONTENT` | string | Inline json config content |
564+
| `OPENCODE_APPNAME` | string | App name for XDG paths (e.g., `opencode-work`) |
564565
| `OPENCODE_DATA_DIR` | string | Path to data directory |
565566
| `OPENCODE_CACHE_DIR` | string | Path to cache directory |
566567
| `OPENCODE_LOG_DIR` | string | Path to log directory |

‎packages/web/src/content/docs/config.mdx‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,41 @@ opencode run "Hello world"
147147

148148
The custom directory is loaded after the global config and `.opencode` directories, so it **can override** their settings.
149149

150+
---
151+
152+
### Profile isolation with custom app name
153+
154+
Use the `OPENCODE_APPNAME` environment variable to create isolated profiles
155+
with separate data, cache, config, and state directories. This is useful for
156+
managing multiple identities (e.g., work and personal) with separate OAuth
157+
credentials, settings, and history.
158+
159+
```bash
160+
# Work profile
161+
OPENCODE_APPNAME=opencode-work opencode
162+
163+
# Personal profile
164+
OPENCODE_APPNAME=opencode-personal opencode
165+
```
166+
167+
Each profile gets its own XDG directories:
168+
169+
- Data: `~/.local/share/opencode-work` (auth tokens, logs, etc.)
170+
- Cache: `~/.cache/opencode-work` (plugins, binaries)
171+
- Config: `~/.config/opencode-work` (settings)
172+
- State: `~/.local/state/opencode-work` (UI state, history)
173+
174+
You can create shell aliases for convenient switching:
175+
176+
```bash
177+
alias oc-work='OPENCODE_APPNAME=opencode-work opencode'
178+
alias oc-personal='OPENCODE_APPNAME=opencode-personal opencode'
179+
```
180+
181+
**Note:** Explicit path overrides (below) take precedence over `OPENCODE_APPNAME`.
182+
183+
---
184+
150185
### Custom data directory
151186

152187
Specify a custom data directory using the `OPENCODE_DATA_DIR`

0 commit comments

Comments
 (0)