fix: respect OPENCODE_CONFIG_DIR environment variable across all config paths

Multiple files were hardcoding ~/.config/opencode paths instead of using
getOpenCodeConfigDir() which respects the OPENCODE_CONFIG_DIR env var.

This broke profile isolation features like OCX ghost mode, where users
set OPENCODE_CONFIG_DIR to a custom path but oh-my-opencode.json and
other configs weren't being read from that location.

Changes:
- plugin-config.ts: Use getOpenCodeConfigDir() directly
- cli/doctor/checks: Use getOpenCodeConfigDir() for auth and config checks
- tools/lsp/config.ts: Use getOpenCodeConfigDir() for LSP config paths
- command loaders: Use getOpenCodeConfigDir() for global command dirs
- hooks: Use getOpenCodeConfigDir() for hook config paths
- config-path.ts: Mark getUserConfigDir() as deprecated
- tests: Ensure OPENCODE_CONFIG_DIR is properly isolated in tests
This commit is contained in:
Nguyen Khac Trung Kien
2026-01-22 12:15:09 +07:00
parent 5187d677d2
commit 22a5c8e64d
11 changed files with 36 additions and 68 deletions
+7 -5
View File
@@ -1,8 +1,8 @@
import { existsSync, readFileSync } from "fs"
import { join } from "path"
import { homedir } from "os"
import { BUILTIN_SERVERS, EXT_TO_LANG, LSP_INSTALL_HINTS } from "./constants"
import type { ResolvedServer, ServerLookupResult } from "./types"
import { getOpenCodeConfigDir } from "../../shared"
interface LspEntry {
disabled?: boolean
@@ -34,10 +34,11 @@ function loadJsonFile<T>(path: string): T | null {
function getConfigPaths(): { project: string; user: string; opencode: string } {
const cwd = process.cwd()
const configDir = getOpenCodeConfigDir({ binary: "opencode" })
return {
project: join(cwd, ".opencode", "oh-my-opencode.json"),
user: join(homedir(), ".config", "opencode", "oh-my-opencode.json"),
opencode: join(homedir(), ".config", "opencode", "opencode.json"),
user: join(configDir, "oh-my-opencode.json"),
opencode: join(configDir, "opencode.json"),
}
}
@@ -199,10 +200,11 @@ export function isServerInstalled(command: string[]): boolean {
}
const cwd = process.cwd()
const configDir = getOpenCodeConfigDir({ binary: "opencode" })
const additionalBases = [
join(cwd, "node_modules", ".bin"),
join(homedir(), ".config", "opencode", "bin"),
join(homedir(), ".config", "opencode", "node_modules", ".bin"),
join(configDir, "bin"),
join(configDir, "node_modules", ".bin"),
]
for (const base of additionalBases) {
+3 -3
View File
@@ -1,7 +1,7 @@
import { tool, type ToolDefinition } from "@opencode-ai/plugin"
import { existsSync, readdirSync, readFileSync } from "fs"
import { join, basename, dirname } from "path"
import { parseFrontmatter, resolveCommandsInText, resolveFileReferencesInText, sanitizeModelField } from "../../shared"
import { parseFrontmatter, resolveCommandsInText, resolveFileReferencesInText, sanitizeModelField, getOpenCodeConfigDir } from "../../shared"
import type { CommandFrontmatter } from "../../features/claude-code-command-loader/types"
import { isMarkdownFile } from "../../shared/file-utils"
import { getClaudeConfigDir } from "../../shared"
@@ -52,10 +52,10 @@ function discoverCommandsFromDir(commandsDir: string, scope: CommandScope): Comm
}
export function discoverCommandsSync(): CommandInfo[] {
const { homedir } = require("os")
const configDir = getOpenCodeConfigDir({ binary: "opencode" })
const userCommandsDir = join(getClaudeConfigDir(), "commands")
const projectCommandsDir = join(process.cwd(), ".claude", "commands")
const opencodeGlobalDir = join(homedir(), ".config", "opencode", "command")
const opencodeGlobalDir = join(configDir, "command")
const opencodeProjectDir = join(process.cwd(), ".opencode", "command")
const userCommands = discoverCommandsFromDir(userCommandsDir, "user")