-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[FEATURE]: Configurable instruction file search boundary and file types #4479
Copy link
Copy link
Closed
Labels
discussionUsed for feature requests, proposals, ideas, etc. Open discussionUsed for feature requests, proposals, ideas, etc. Open discussion
Description
Feature hasn't been suggested before.
- I have verified this feature I'm about to request hasn't been suggested before.
Describe the enhancement you want to request
Feature Request: Configurable AGENTS.md Search Behavior
Problem
OpenCode searches for instruction files (AGENTS.md, CLAUDE.md, CONTEXT.md) but has two limitations:
- Search stops at git repository root - Cannot find AGENTS.md files in parent directories above the repository
- Only first file type is loaded - If AGENTS.md exists, CLAUDE.md is never checked (due to
breakstatement)
Example: Monorepo Issue
/workspace/company-monorepo/
├── AGENTS.md ← Cannot be found
└── services/
├── AGENTS.md ← Cannot be found
└── my-service/
└── .git/ ← Search stops here
└── src/working-here/
Code: packages/opencode/src/session/system.ts:74-80
for (const localRuleFile of LOCAL_RULE_FILES) {
const matches = await Filesystem.findUp(localRuleFile, Instance.directory, Instance.worktree)
if (matches.length > 0) {
matches.forEach((path) => paths.add(path))
break // ← Stops after first file type found
}
}Proposed Solution
Add two configuration options in opencode.json:
Defaults (Backward Compatible)
{
"instructions": {
"searchBoundary": "git-root",
"fileTypes": ["AGENTS.md", "CLAUDE.md", "CONTEXT.md"],
},
}Examples
Monorepo setup:
{
"instructions": {
"searchBoundary": "filesystem-root",
"fileTypes": ["AGENTS.md"],
},
}Use both AGENTS.md and CLAUDE.md:
{
"instructions": {
"fileTypes": ["AGENTS.md", "CLAUDE.md"],
},
}Implementation
1. Update config schema (packages/opencode/src/config/config.ts):
instructions: z.object({
searchBoundary: z.enum(["git-root", "filesystem-root"]).default("git-root"),
fileTypes: z
.array(z.enum(["AGENTS.md", "CLAUDE.md", "CONTEXT.md"]))
.default(["AGENTS.md", "CLAUDE.md", "CONTEXT.md"]),
}).optional()2. Update search logic (packages/opencode/src/session/system.ts):
const fileTypes = config.instructions?.fileTypes ?? LOCAL_RULE_FILES
const searchStop = config.instructions?.searchBoundary === "filesystem-root" ? undefined : Instance.worktree
for (const localRuleFile of fileTypes) {
const matches = await Filesystem.findUp(localRuleFile, Instance.directory, searchStop)
matches.forEach((path) => paths.add(path))
// Remove break statement - search all file types
}Benefits
- ✅ Monorepo support
- ✅ Backward compatible
- ✅ Choose specific file formats
- ✅ Load multiple file types together
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
discussionUsed for feature requests, proposals, ideas, etc. Open discussionUsed for feature requests, proposals, ideas, etc. Open discussion
{ "instructions": { "searchBoundary": "git-root" | "filesystem-root", "fileTypes": ["AGENTS.md", "CLAUDE.md", "CONTEXT.md"] } }