diff --git a/packages/opencode/src/session/instruction.ts b/packages/opencode/src/session/instruction.ts index bd50980159..5d91066b41 100644 --- a/packages/opencode/src/session/instruction.ts +++ b/packages/opencode/src/session/instruction.ts @@ -122,6 +122,13 @@ export const layer: Layer.Layer() + for (const file of globalFiles()) { + if (yield* fs.existsSafe(file)) { + paths.add(path.resolve(file)) + break + } + } + // The first project-level match wins so we don't stack AGENTS.md/CLAUDE.md from every ancestor. if (!Flag.OPENCODE_DISABLE_PROJECT_CONFIG) { for (const file of FILES) { @@ -133,13 +140,6 @@ export const layer: Layer.Layer { const rules = yield* svc.system() expect(rules).toHaveLength(2) - expect(rules).toContain( - `Instructions from: ${path.join(projectTmp.path, "AGENTS.md")}\n# Project Instructions`, - ) - expect(rules).toContain( + expect(rules[0]).toBe( `Instructions from: ${path.join(globalTmp.path, "AGENTS.md")}\n# Global Instructions`, ) + expect(rules[1]).toBe( + `Instructions from: ${path.join(projectTmp.path, "AGENTS.md")}\n# Project Instructions`, + ) }), ), ),