feat: instruction-aware generation — complement existing AGENTS.md, CLAUDE.md, and .instructions.md files#17
Merged
digitarald merged 2 commits intomicrosoft:mainfrom Feb 26, 2026
Conversation
…LAUDE.md, and .instructions.md files Detect existing AI instruction files (AGENTS.md, CLAUDE.md, .instructions.md) before generating copilot-instructions.md and steer the model to complement rather than duplicate their content. - detectExistingInstructions() walks the repo tree for AGENTS.md and CLAUDE.md, scans .github/instructions/ for modular .instructions.md files - buildExistingInstructionsSection() emits prompt context listing found files with output rules that prevent content duplication - 13 new tests covering detection and prompt section generation Relates to microsoft#6
There was a problem hiding this comment.
Pull request overview
This PR implements instruction-aware generation to address issue #6. It teaches the agentrc instructions command to detect existing instruction files (AGENTS.md, CLAUDE.md, and .instructions.md) in a repository and generate complementary content instead of duplicating what those files already provide. The feature adds 167 tokens to the generation prompt when instruction files exist but saves 307 tokens in output for the test repository, resulting in a net savings of 140 tokens.
Changes:
- Added detection functions to find existing AGENTS.md, CLAUDE.md, and .instructions.md files across the repository
- Modified both
generateCopilotInstructionsandgenerateAreaInstructionsto use detected instruction context when building prompts - Added comprehensive test coverage with 13 new test cases covering empty repos, nested files, multiple formats, and edge cases
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/services/instructions.ts | Implements detection of existing instruction files and integrates instruction-aware prompt generation into both copilot-instructions and area-specific instruction generation workflows |
| src/services/tests/instructions.test.ts | Adds 13 test cases covering detectExistingInstructions and buildExistingInstructionsSection functions with comprehensive edge case coverage |
- Add explicit symlink filter in findModularInstructionFiles for consistency with findInstructionMarkerFiles - Fix missing newline before final bullet in area instruction prompt - Add test verifying symlinked AGENTS.md/CLAUDE.md are excluded
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TL;DR
.github/instructions/)Problem
Relates to #6 — "current instruction set is not considered when generating instructions".
agentrc instructionsgenerates.github/copilot-instructions.mdfrom scratch without considering what instruction files already exist in the repo. When a repo already has AGENTS.md files (from tools like APM or hand-authored), CLAUDE.md files (for Claude Code), or modular.github/instructions/*.instructions.mdfiles, the generated output restates content already delivered by those files — wasting context window budget.How the duplication happens
A repo has existing instruction files — AGENTS.md (via the agents.md standard), CLAUDE.md (for Claude Code), or
.github/instructions/*.instructions.md(VS Code Copilot's native modular format). These may be hand-authored, generated by tools like APM, or a mix.agentrc instructionsexplores the codebase, finds the same conventions those files already describe, and restates them incopilot-instructions.md.The LLM that later reads the repo sees duplicate content — once from the existing instruction files and again from copilot-instructions.md.
Solution
This PR teaches
agentrc instructionsto detect existing instruction files in the repo and steer the model to generate complementary content instead of duplicating what those files already deliver.What it detects
AGENTS.mdCLAUDE.md*.instructions.md.github/instructions/The walker excludes
.git,node_modules,apm_modules, and.apmdirectories. Symlinks are skipped for safety.How it works
When instruction files are found, a context section is appended to the generation prompt listing every detected file path and 3 output rules that steer the model to defer rather than restate.
System message (adds 4 words when instruction files exist):
Prompt section (appended — 167 tokens for test repo with 9 instruction files):
Reproducible test
Test target:
danielmeppiel/corporate-website— a repo with 5 AGENTS.md and 4 CLAUDE.md files.Comparison
main)See [AGENTS.md]linkDesign decisions
Format-agnostic — Detects all three major instruction file formats (AGENTS.md, CLAUDE.md, .instructions.md) regardless of how they were created. No dependency on any specific tool.
No prompt when empty — If no instruction files exist,
buildExistingInstructionsSection()returns"". Zero overhead for repos without existing instructions.Output rules steer writing, not reading — The prompt doesn't tell the model what to avoid reading. It tells the model what to write: defer to existing files, use markdown links as pointers, focus on project-specific conventions not already covered.
Walker safety — Uses
readdir({ withFileTypes: true })to avoid extrastat()calls and skips symlinks to prevent infinite loops.What's NOT in this PR
agentrc analyze,agentrc eval, or any other commandfs/promises(Node built-in)