Skip to content

Commit 4c67545

Browse files
Add AGENTS.md support for project instructions (#142)
Read AGENTS.md from project root and pass its content to the Claude SDK via systemPrompt append, and include it in Ollama offline context. This allows users who maintain AGENTS.md files in their projects to have those instructions automatically loaded into chat sessions. Co-authored-by: Claude <noreply@anthropic.com>
1 parent 31e27b2 commit 4c67545

2 files changed

Lines changed: 31 additions & 6 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ By [21st.dev](https://21st.dev) team
1919
| **Integrated Terminal** |||
2020
| **Plan Mode** |||
2121
| **MCP Support** |||
22-
| **Memory (CLAUDE.md)** |||
22+
| **Memory (CLAUDE.md & AGENTS.md)** |||
2323
| **Skills & Slash Commands** |||
2424
| **Custom Subagents** |||
2525
| **Subscription & API Key Support** |||

src/main/lib/trpc/routers/claude.ts

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,20 @@ export const claudeRouter = router({
979979
})
980980
}
981981

982+
// Read AGENTS.md from project root if it exists
983+
let agentsMdContent: string | undefined
984+
try {
985+
const agentsMdPath = path.join(input.cwd, "AGENTS.md")
986+
agentsMdContent = await fs.readFile(agentsMdPath, "utf-8")
987+
if (agentsMdContent.trim()) {
988+
console.log(`[claude] Found AGENTS.md at ${agentsMdPath} (${agentsMdContent.length} chars)`)
989+
} else {
990+
agentsMdContent = undefined
991+
}
992+
} catch {
993+
// AGENTS.md doesn't exist or can't be read - that's fine
994+
}
995+
982996
// For Ollama: embed context AND history directly in prompt
983997
// Ollama doesn't have server-side sessions, so we must include full history
984998
let finalQueryPrompt: string | AsyncIterable<any> = prompt
@@ -1076,7 +1090,11 @@ IMPORTANT: When using tools, use these EXACT parameter names:
10761090
10771091
When asked about the project, use Glob to find files and Read to examine them.
10781092
Be concise and helpful.
1079-
[/CONTEXT]
1093+
[/CONTEXT]${agentsMdContent ? `
1094+
1095+
[AGENTS.MD]
1096+
${agentsMdContent}
1097+
[/AGENTS.MD]` : ''}
10801098
10811099
${historyText}[CURRENT REQUEST]
10821100
${prompt}
@@ -1086,10 +1104,17 @@ ${prompt}
10861104
}
10871105

10881106
// System prompt config - use preset for both Claude and Ollama
1089-
const systemPromptConfig = {
1090-
type: "preset" as const,
1091-
preset: "claude_code" as const,
1092-
}
1107+
// If AGENTS.md exists, append its content to the system prompt
1108+
const systemPromptConfig = agentsMdContent
1109+
? {
1110+
type: "preset" as const,
1111+
preset: "claude_code" as const,
1112+
append: `\n\n# AGENTS.md\nThe following are the project's AGENTS.md instructions:\n\n${agentsMdContent}`,
1113+
}
1114+
: {
1115+
type: "preset" as const,
1116+
preset: "claude_code" as const,
1117+
}
10931118

10941119
const queryOptions = {
10951120
prompt: finalQueryPrompt,

0 commit comments

Comments
 (0)