From 517d18d40593412ba445b33930a7267c968bb514 Mon Sep 17 00:00:00 2001 From: Levi Neely Date: Thu, 30 Jul 2026 09:39:58 +0200 Subject: [PATCH] agent: inject AGENTS.md from cwd into user context MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- agent/turn.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/agent/turn.go b/agent/turn.go index 1d5ecee..d3afd09 100644 --- a/agent/turn.go +++ b/agent/turn.go @@ -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") }