Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix(core): create redcode.json when hook import has no config to edit
`Hook.importClaude` writes into the project's highest-priority config
document, which now correctly resolves to a Redcode-named file when one
exists. Only a project with no config at all falls through to creating one,
and that path still used the OpenCode name — the one remaining place where
a brand-new file would be created under the old name.

Claude-Session: https://claude.ai/code/session_016rycAgbtqsRQH4qBv8nkE7
  • Loading branch information
filipeforattini committed Aug 16, 2026
commit 684344c78caf35f806c380b315652897cf88c87f
5 changes: 4 additions & 1 deletion packages/core/src/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,10 @@ const layer = Layer.effect(
!FSUtil.contains(global.config, entry.path) &&
FSUtil.contains(location.project.directory, entry.path),
)
const target = documents.at(-1)?.path ?? path.join(location.project.directory, "opencode.json")
// Prefer the highest-priority config the project already has, whatever it is named, so
// hooks never land in a second file beside an existing one. Only a project with no config
// at all gets one created, under the Redcode name.
const target = documents.at(-1)?.path ?? path.join(location.project.directory, "redcode.json")
const current = (yield* fs.readFileStringSafe(target).pipe(Effect.orDie)) ?? "{}\n"
const next = applyEdits(
current,
Expand Down
4 changes: 3 additions & 1 deletion packages/core/test/hook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ describe("HookV2", () => {
path.join(project.path, "state"),
)
const written = await fs.readFile(path.join(project.path, "opencode.jsonc"), "utf8")
// The existing legacy-named config is edited in place; no redcode.json appears beside it.
expect(result.target).toBe(path.join(project.path, "opencode.jsonc"))
expect(result.imported).toBe(1)
expect(result.restart_required).toBe(true)
expect(written).toContain("// keep me")
Expand All @@ -144,7 +146,7 @@ describe("HookV2", () => {
project.path,
path.join(project.path, "state"),
)
expect(result.target).toBe(path.join(project.path, "opencode.json"))
expect(result.target).toBe(path.join(project.path, "redcode.json"))
expect(await fs.readFile(global, "utf8")).toBe(JSON.stringify({ model: "global/model" }))
})
})
Loading