agent: inject AGENTS.md from cwd into user context

If AGENTS.md exists in the working directory, its contents are injected
as a user message at session start and after compaction (via spawnContext).
Not part of the system prompt — lives in conversation history.
This commit is contained in:
Levi Neely 2026-07-30 09:39:58 +02:00
parent f8459021b7
commit 517d18d405
1 changed files with 6 additions and 0 deletions

View File

@ -420,6 +420,12 @@ func (ag *Agent) spawnContext(ctx context.Context) string {
if result.Context != "" {
parts = append(parts, result.Context)
}
// Inject AGENTS.md from the working directory if it exists.
if cwd := ag.effectiveCwd(); cwd != "" {
if data, err := os.ReadFile(cwd + "/AGENTS.md"); err == nil && len(data) > 0 {
parts = append(parts, string(data))
}
}
return strings.Join(parts, "\n\n---\n\n")
}