Skip to content

Commit c00206b

Browse files
fix(core): move global config to ~/.red/redcode/config.json[c] (#46)
Closes #27. The XDG config directory was renamed to redcode but the file inside stayed opencode.json[c], which makes the live config read like a leftover and traps users editing the wrong file. - Primary config directory moves from ~/.config/redcode/ to ~/.red/redcode/, joining redskilled under the RedDB family. Data, cache, and state directories follow. - Primary file name becomes config.jsonc (config.json as alias). The transitional redcode.json[c] and the legacy opencode.json[c] are still read, with config.* winning the merge. The XDG directory is also still searched as a fallback so existing installs keep working without manual migration. - Customize-opencode skill, README, and mcp default-creation all point at the new paths; OPENCODE_* env vars still override. Co-authored-by: Claude Opus 4.6 <[email protected]>
1 parent 9853dd0 commit c00206b

12 files changed

Lines changed: 115 additions & 51 deletions

File tree

‎.changeset/config-redcode-home.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"opencode": patch
3+
---
4+
5+
Move the global config directory from `~/.config/redcode/` to the RedDB family at `~/.red/redcode/` and rename the global config file to `config.jsonc` (with `config.json` as an alias). The XDG directory is still read as a fallback so existing installs keep working without manual migration; the transitional `redcode.json` / `redcode.jsonc` and the legacy `opencode.json` / `opencode.jsonc` names are still read everywhere the primary `config.*` name is, and the primary file always wins on merge.

‎README.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,11 @@ does not import the CLI that hosts it.
235235
The product is Redcode; most of the source still says OpenCode. Workspace packages are
236236
`@opencode-ai/*`, the package that becomes the binary is literally named `opencode`, and environment
237237
variables are `OPENCODE_*`. What *is* renamed is everything a user touches: the `redcode` binary, the
238-
`redcode` XDG data and cache directories, the npm namespace, and the agent's identity over ACP.
238+
`~/.red/redcode/` data, cache, state, and config directories (with the `~/.config/redcode/` XDG directory
239+
still read as a fallback so existing installs keep working), the npm namespace, and the agent's identity
240+
over ACP. The global config file is `~/.red/redcode/config.jsonc` (or `config.json`); the transitional
241+
`redcode.json` / `redcode.jsonc` and the legacy `opencode.json` / `opencode.jsonc` names are still read
242+
everywhere the primary `config.*` name is, and the primary file always wins on merge.
239243

240244
Leaving the internals alone is deliberate. A rename would touch every file, bury the real changes in
241245
noise, and make our work harder to read against upstream's — so expect the mismatch and read

‎packages/core/src/config.ts‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,17 @@ const layer = Layer.effect(
144144
const location = yield* Location.Service
145145
const policy = yield* Policy.Service
146146
// Ordered from lowest to highest precedence. Every name present in a directory is
147-
// loaded and merged, so a Redcode-named file overrides the legacy OpenCode-named
148-
// one field by field rather than replacing it. A directory holding only the
149-
// OpenCode-named file keeps behaving exactly as before.
150-
const names = ["opencode.json", "opencode.jsonc", "redcode.json", "redcode.jsonc"]
147+
// loaded and merged, so a primary `config.json[c]` overrides the legacy `opencode.*`
148+
// and transitional `redcode.*` ones field by field rather than replacing them. A
149+
// directory holding only the OpenCode-named file keeps behaving exactly as before.
150+
const names = [
151+
"opencode.json",
152+
"opencode.jsonc",
153+
"redcode.json",
154+
"redcode.jsonc",
155+
"config.json",
156+
"config.jsonc",
157+
]
151158
const decodeOptions = { errors: "all", onExcessProperty: "ignore", propertyOrder: "original" } as const
152159
const decodeInfo = Schema.decodeUnknownOption(Info, decodeOptions)
153160
const decodeV1Info = Schema.decodeUnknownOption(ConfigV1.Info, decodeOptions)
@@ -179,6 +186,14 @@ const layer = Layer.effect(
179186
})
180187

181188
const globalDirectory = AbsolutePath.make(global.config)
189+
const legacyConfigDir = global.legacyConfig
190+
// Read the legacy XDG-style directory as a fallback so existing installs that still
191+
// hold their config at `~/.config/redcode/` keep working without manual migration.
192+
// A directory holding only the legacy `opencode.jsonc` keeps behaving exactly as before.
193+
const legacyGlobalDirectory =
194+
legacyConfigDir && path.resolve(legacyConfigDir) !== path.resolve(global.config)
195+
? AbsolutePath.make(legacyConfigDir)
196+
: null
182197
const locationIsGlobal = path.resolve(location.directory) === path.resolve(global.config)
183198
// Read configuration once when this location opens. Later calls reuse these
184199
// values until the location is reopened.

‎packages/core/src/global.ts‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@ import { Flag } from "./flag/flag"
88
import { makeGlobalNode } from "./effect/app-node"
99

1010
const app = "redcode"
11-
const data = path.join(xdgData!, app)
12-
const cache = path.join(xdgCache!, app)
13-
const config = path.join(xdgConfig!, app)
14-
const state = path.join(xdgState!, app)
11+
const home = process.env.OPENCODE_TEST_HOME ?? os.homedir()
12+
13+
// Primary paths live under the RedDB family alongside redskilled
14+
// (`~/.red/redskilled`), so `redcode` joins it instead of splitting across XDG.
15+
const redcodeHome = path.join(home, ".red", app)
16+
const data = path.join(redcodeHome, "data")
17+
const cache = path.join(redcodeHome, "cache")
18+
const config = redcodeHome
19+
const state = path.join(redcodeHome, "state")
1520
const tmp = path.join(os.tmpdir(), app)
1621

1722
const paths = {
@@ -26,6 +31,7 @@ const paths = {
2631
config,
2732
state,
2833
tmp,
34+
legacyConfig: path.join(xdgConfig!, app),
2935
}
3036

3137
export const Path = paths
@@ -54,6 +60,7 @@ export interface Interface {
5460
readonly bin: string
5561
readonly log: string
5662
readonly repos: string
63+
readonly legacyConfig?: string
5764
}
5865

5966
export function make(input: Partial<Interface> = {}): Interface {
@@ -67,6 +74,7 @@ export function make(input: Partial<Interface> = {}): Interface {
6774
bin: Path.bin,
6875
log: Path.log,
6976
repos: Path.repos,
77+
legacyConfig: Path.legacyConfig,
7078
...input,
7179
}
7280
}

‎packages/core/src/plugin/skill/customize-opencode.md‎

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,28 @@ already-loaded config until then.
3737

3838
## Where files live
3939

40-
| Scope | Path |
41-
| ----------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
42-
| Project config | `./redcode.json`, `./redcode.jsonc`, or `.opencode/redcode.json` (opencode walks up from the cwd to the worktree root) |
43-
| Global config | `~/.config/redcode/redcode.json` or `~/.config/redcode/redcode.jsonc` (NOT `~/.opencode/`) |
44-
| Project agents | `.opencode/agent/<name>.md` or `.opencode/agents/<name>.md` |
45-
| Global agents | `~/.config/redcode/agent(s)/<name>.md` |
46-
| Project commands | `.opencode/command/<name>.md` or `.opencode/commands/<name>.md` |
47-
| Global commands | `~/.config/redcode/command(s)/<name>.md` |
48-
| Project skills | `.opencode/skill(s)/<name>/SKILL.md` |
49-
| Global skills | `~/.config/redcode/skill(s)/<name>/SKILL.md` |
50-
| External skills (auto-loaded) | `~/.claude/skills/<name>/SKILL.md`, `~/.agents/skills/<name>/SKILL.md` |
40+
| Scope | Path |
41+
| ----------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
42+
| Project config | `./config.jsonc`, `./config.json`, or `.opencode/config.jsonc` (opencode walks up from the cwd to the worktree root) |
43+
| Global config | `~/.red/redcode/config.jsonc` or `~/.red/redcode/config.json` (NOT `~/.opencode/`) |
44+
| Project agents | `.opencode/agent/<name>.md` or `.opencode/agents/<name>.md` |
45+
| Global agents | `~/.red/redcode/agent(s)/<name>.md` |
46+
| Project commands | `.opencode/command/<name>.md` or `.opencode/commands/<name>.md` |
47+
| Global commands | `~/.red/redcode/command(s)/<name>.md` |
48+
| Project skills | `.opencode/skill(s)/<name>/SKILL.md` |
49+
| Global skills | `~/.red/redcode/skill(s)/<name>/SKILL.md` |
50+
| External skills (auto-loaded) | `~/.claude/skills/<name>/SKILL.md`, `~/.agents/skills/<name>/SKILL.md` |
5151

5252
Configs from each scope are deep-merged. Project overrides global. Unknown
5353
top-level keys in the config file are rejected with `ConfigInvalidError`.
5454

55-
The legacy `opencode.json` / `opencode.jsonc` names are still read everywhere the
56-
`redcode.*` names are. When a directory holds both, they are merged and the
57-
`redcode.*` file wins. Edit the file that already exists rather than creating a
58-
second one beside it.
55+
The legacy `redcode.json` / `redcode.jsonc` and the older `opencode.json` /
56+
`opencode.jsonc` names are still read everywhere the primary `config.jsonc` /
57+
`config.json` names are. When a directory holds several, they are merged and the
58+
primary `config.*` file wins. The XDG-style `~/.config/redcode/` directory is
59+
also still searched as a fallback so existing installs keep working without
60+
manual migration; edit the file that already exists rather than creating a second
61+
one beside it.
5962

6063
## Config file fields
6164

‎packages/core/test/config/config.test.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ function testLayer(
2626
globalDirectory = path.join(directory, "global"),
2727
projectDirectory = directory,
2828
vcs?: Project.Vcs,
29+
legacyConfigDirectory = path.join(directory, "legacy-config"),
2930
) {
3031
const locationLayer = Layer.succeed(
3132
Location.Service,
@@ -38,7 +39,7 @@ function testLayer(
3839
)
3940
return AppNodeBuilder.build(LayerNode.group([Config.node, Policy.node]), [
4041
[Location.node, locationLayer],
41-
[Global.node, Global.layerWith({ config: globalDirectory })],
42+
[Global.node, Global.layerWith({ config: globalDirectory, legacyConfig: legacyConfigDirectory })],
4243
])
4344
}
4445

@@ -315,22 +316,22 @@ describe("Config", () => {
315316
),
316317
)
317318

318-
it.live("does not load legacy config.json files", () =>
319+
it.live("loads the primary config.jsonc at the project level", () =>
319320
Effect.acquireRelease(
320321
Effect.promise(() => tmpdir()),
321322
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
322323
).pipe(
323324
Effect.flatMap((tmp) =>
324325
Effect.gen(function* () {
325326
yield* Effect.promise(() =>
326-
fs.writeFile(path.join(tmp.path, "config.json"), JSON.stringify({ $schema: "legacy" })),
327+
fs.writeFile(path.join(tmp.path, "config.jsonc"), JSON.stringify({ $schema: "primary" })),
327328
)
328329

329330
return yield* Effect.gen(function* () {
330331
const config = yield* Config.Service
331332
const documents = (yield* config.entries()).filter((entry) => entry.type === "document")
332333

333-
expect(documents).toHaveLength(0)
334+
expect(documents.map((document) => document.info.$schema)).toEqual(["primary"])
334335
}).pipe(Effect.provide(testLayer(tmp.path)))
335336
}),
336337
),

‎packages/opencode/src/cli/cmd/mcp.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -392,11 +392,11 @@ export const McpLogoutCommand = effectCmd({
392392
})
393393

394394
async function resolveConfigPath(baseDir: string, global = false) {
395-
// Check for existing config files (check the .opencode/ subdirectory too). Redcode names come
396-
// first so that when both exist the edit lands on the file that also wins when config is read;
395+
// Check for existing config files (check the .opencode/ subdirectory too). Primary Redcode names
396+
// come first so that when both exist the edit lands on the file that also wins when config is read;
397397
// a legacy-only directory still gets edited in place rather than gaining a second file, and only
398-
// a directory with no config at all gets a redcode.json created.
399-
const names = ["redcode.json", "redcode.jsonc", "opencode.json", "opencode.jsonc"]
398+
// a directory with no config at all gets a `config.jsonc` created.
399+
const names = ["config.jsonc", "config.json", "redcode.jsonc", "redcode.json", "opencode.jsonc", "opencode.json"]
400400
const candidates = names.map((name) => path.join(baseDir, name))
401401

402402
if (!global) {
@@ -409,8 +409,8 @@ async function resolveConfigPath(baseDir: string, global = false) {
409409
}
410410
}
411411

412-
// Default to redcode.json if none exist
413-
return path.join(baseDir, "redcode.json")
412+
// Default to the primary `config.jsonc` if none exist
413+
return path.join(baseDir, "config.jsonc")
414414
}
415415

416416
async function addMcpToConfig(name: string, mcpConfig: ConfigMCPV1.Info, configPath: string) {

‎packages/opencode/src/config/config.ts‎

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ export const use = serviceUse(Service)
139139
function globalConfigFile() {
140140
// Highest precedence first: an existing file is always reused, so a user who only has
141141
// the legacy OpenCode-named file keeps writing to it instead of gaining a second file.
142-
// Only a fresh install with no config at all creates the Redcode-named one.
143-
const candidates = ["redcode.jsonc", "redcode.json", "opencode.jsonc", "opencode.json", "config.json"].map((file) =>
142+
// Only a fresh install with no config at all creates the primary `config.jsonc` one.
143+
const candidates = ["config.jsonc", "config.json", "redcode.jsonc", "redcode.json", "opencode.jsonc", "opencode.json"].map((file) =>
144144
path.join(Global.Path.config, file),
145145
)
146146
for (const file of candidates) {
@@ -258,23 +258,31 @@ const layer = Layer.effect(
258258
.pipe(Effect.catch(() => Effect.void))
259259
}
260260
}
261-
result = mergeConfig(result, yield* loadFile(path.join(Global.Path.config, "config.json"), env))
262-
result = mergeConfig(result, yield* loadFile(path.join(Global.Path.config, "opencode.json"), env))
263-
result = mergeConfig(result, yield* loadFile(path.join(Global.Path.config, "opencode.jsonc"), env))
264-
result = mergeConfig(result, yield* loadFile(path.join(Global.Path.config, "redcode.json"), env))
265-
result = mergeConfig(result, yield* loadFile(path.join(Global.Path.config, "redcode.jsonc"), env))
266-
267-
const legacy = path.join(Global.Path.config, "config")
268-
if (existsSync(legacy)) {
261+
// Ordered lowest to highest: legacy XDG-named files first so the primary Redcode-named
262+
// ones override them field by field rather than replacing them. An existing install with
263+
// only the legacy OpenCode-named file keeps behaving exactly as before.
264+
const legacyDir = Global.Path.legacyConfig
265+
const legacyFiles = ["opencode.json", "opencode.jsonc", "redcode.json", "redcode.jsonc", "config.json", "config.jsonc"]
266+
for (const file of legacyFiles) {
267+
result = mergeConfig(result, yield* loadFile(path.join(legacyDir, file), env))
268+
}
269+
const primary = Global.Path.config
270+
const primaryFiles = ["opencode.json", "opencode.jsonc", "redcode.json", "redcode.jsonc", "config.json", "config.jsonc"]
271+
for (const file of primaryFiles) {
272+
result = mergeConfig(result, yield* loadFile(path.join(primary, file), env))
273+
}
274+
275+
const legacyToml = path.join(Global.Path.config, "config")
276+
if (existsSync(legacyToml)) {
269277
yield* Effect.promise(() =>
270-
import(pathToFileURL(legacy).href, { with: { type: "toml" } })
278+
import(pathToFileURL(legacyToml).href, { with: { type: "toml" } })
271279
.then(async (mod) => {
272280
const { provider, model, ...rest } = mod.default
273281
if (provider && model) result.model = `${provider}/${model}`
274282
result["$schema"] = "https://opencode.ai/config.json"
275283
result = mergeConfig(result, rest)
276284
await fsNode.writeFile(path.join(Global.Path.config, "config.json"), JSON.stringify(result, null, 2))
277-
await fsNode.unlink(legacy)
285+
await fsNode.unlink(legacyToml)
278286
})
279287
.catch(() => {}),
280288
)
@@ -430,7 +438,14 @@ const layer = Layer.effect(
430438

431439
for (const dir of directories) {
432440
if (dir.endsWith(".opencode") || dir === Flag.OPENCODE_CONFIG_DIR) {
433-
for (const file of ["opencode.json", "opencode.jsonc", "redcode.json", "redcode.jsonc"]) {
441+
for (const file of [
442+
"opencode.json",
443+
"opencode.jsonc",
444+
"redcode.json",
445+
"redcode.jsonc",
446+
"config.json",
447+
"config.jsonc",
448+
]) {
434449
const source = path.join(dir, file)
435450
yield* Effect.logDebug(`loading config from ${source}`)
436451
yield* merge(source, yield* loadFile(source, authEnv))
@@ -522,7 +537,14 @@ const layer = Layer.effect(
522537

523538
const managedDir = ConfigManaged.managedConfigDir()
524539
if (existsSync(managedDir)) {
525-
for (const file of ["opencode.json", "opencode.jsonc", "redcode.json", "redcode.jsonc"]) {
540+
for (const file of [
541+
"opencode.json",
542+
"opencode.jsonc",
543+
"redcode.json",
544+
"redcode.jsonc",
545+
"config.json",
546+
"config.jsonc",
547+
]) {
526548
const source = path.join(managedDir, file)
527549
yield* merge(source, yield* loadFile(source), "global")
528550
}

‎packages/opencode/src/config/paths.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const directories = Effect.fn("ConfigPaths.directories")(function* (direc
2626
const afs = yield* FSUtil.Service
2727
return unique([
2828
Global.Path.config,
29+
Global.Path.legacyConfig,
2930
...(!Flag.OPENCODE_DISABLE_PROJECT_CONFIG
3031
? yield* afs.up({
3132
targets: [".opencode"],

‎packages/opencode/src/config/tui-migrate.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,12 @@ async function backupAndStripLegacy(file: string, source: string) {
115115
async function opencodeFiles(input: { directories: string[]; cwd: string }) {
116116
const files = [
117117
...ConfigPaths.fileInDirectory(Global.Path.config, "opencode"),
118-
...(await Filesystem.findUp(["opencode.json", "opencode.jsonc"], input.cwd, undefined, { rootFirst: true })),
118+
...(await Filesystem.findUp(
119+
["opencode.json", "opencode.jsonc", "redcode.json", "redcode.jsonc", "config.json", "config.jsonc"],
120+
input.cwd,
121+
undefined,
122+
{ rootFirst: true },
123+
)),
119124
]
120125
for (const dir of unique(input.directories)) {
121126
files.push(...ConfigPaths.fileInDirectory(dir, "opencode"))

0 commit comments

Comments
 (0)