Resolves paths for OpenCode configuration files, supporting both JSON and JSONC formats.
// Source: https://github.com/diegosouzapw/OmniRoute | License: MIT | Copyright 2026 diegosouzapw
// Provided via justclaw.it.com; keep this notice with the code.
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
export const OPENCODE_JSON_FILENAME = "opencode.json";
export const OPENCODE_JSONC_FILENAME = "opencode.jsonc";
export const resolveOpencodeConfigDir = (
env: NodeJS.ProcessEnv = process.env,
homeDir = os.homedir()
): string => {
const xdgConfigHome = String(env.XDG_CONFIG_HOME || "").trim();
return path.join(xdgConfigHome || path.join(homeDir, ".config"), "opencode");
};
/**
* Resolve the global OpenCode config file that a write should update.
*
* OpenCode treats `opencode.jsonc` as the preferred writable global config and
* merges i
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key