agent-instructions-reader
agentInstructionsReader.ts discovers and reads agent instruction files (AGENTS.md, CLAUDE.md, etc.) from the workspace and injects them into the Copilot Chat system prompt.
Scope
src/agentInstructionsReader.ts— file discovery and reading utilities.src/copilotChatParticipant.ts— consumer that injects instructions into the system prompt.
Search paths (in priority order)
The reader checks these paths relative to each workspace folder root:
AGENTS.mdCLAUDE.md.claude/AGENTS.md.claude/CLAUDE.md.github/copilot-instructions.md.cursorrules.ai/agents.mddocs/AGENTS.mddocs/CLAUDE.md
First match wins per workspace folder. Use readAllAgentInstructions() to collect all matches.
Rules
- Auto-inject on every chat. When the participant builds the Ollama message list, it calls
readAgentInstructions()before the system prompt is finalized. If a file is found, its content is appended to the system prompt with a source header. - No caching. Instructions are read fresh on every message so live edits to AGENTS.md take effect immediately.
- UTF-8 only. Non-UTF-8 files are skipped; no encoding detection.
- Silent on missing files. If no instruction file exists, the chat proceeds normally with only the base system prompt.
- Source attribution.
formatInstructionsForPrompt()prepends[Instructions from <path>]so the model knows where the context came from. - Size limits. The raw file content is injected as-is; very large instruction files will consume context window. There is no automatic truncation yet.
Slash command
/instructions — shows the user which file was found and a 500-character preview of its content.
Common mistakes
- Adding a search path that is too generic (e.g.,
README.md) — would pollute the system prompt with unrelated content. - Forgetting that the reader scans all workspace folders in a multi-root workspace.
- Expecting the instructions to persist across VS Code restarts — they are read from disk every time.
Testing
Test by:
- Creating an
AGENTS.mdin the workspace root with a short instruction. - Typing
@manulai helloand confirming the response follows the instruction. - Running
@manulai /instructionsto confirm the file is detected. - Renaming the file to
CLAUDE.mdand confirming it is still found.
Source: alexbeatnik/ManulAI — distributed by TomeVault.