Constellation of glowing amber instruction-rule nodes interconnected by threads of light, auto-loading guardrails activating in context
Chapter 10

Instruction Files & Agents

The guardrail system: what each file covers, when it activates, and how agents review your code.

How Auto-Loading Works

Each instruction file has an applyTo glob pattern in its YAML frontmatter. When you edit a file matching that pattern, the instruction auto-loads into the AI's context. No manual action needed, it's the difference between drowning the AI in every rule you have and having the right guidance whisper only when it's relevant. (For full details on writing your own applyTo patterns, see Chapter 9.)

Example: security.instructions.md
---
description: Security best practices, input validation, auth, secrets
applyTo: "**/auth/**,**/security/**,**/middleware/**"
---
# Security Rules
- Parameterized queries only, never string interpolation in SQL
- Input validation at system boundaries
- No secrets in code, use environment variables or secret managers
...

A Concrete Scenario

Say you ask Copilot Chat to make a change to src/auth/token-validator.cs. Here's what auto-loads, and why each one matters:

File that loadsWhy it matchedWhat it whispers to the AI
architecture-principles.instructions.mdUniversal, applyTo: "**"Stop! Before writing code, ask the 5 architecture questions. Don't bypass scope, don't skip tests.
security.instructions.mdPath matched **/auth/**Parameterized queries only. No secrets in code. Validate inputs at every boundary. OWASP Top 10 defense patterns.
auth.instructions.mdPath matched **/auth/**JWT/OIDC patterns, token expiry rules, RBAC enforcement, multi-tenant isolation guards.
testing.instructions.mdUniversal, applyTo: "**"Tests required for new behavior. Use the project's test framework. Cover edge cases (expired token, tampered signature).

The AI now has 4 focused instruction files in its context, not 17. If you switch to editing src/db/UserRepository.cs, security stays loaded but auth swaps out for database.instructions.md. The right rules whisper at the right time, without you doing anything.

Below is the full catalog: which files exist, what each covers, and which patterns trigger them.

Universal Files (All Presets)

These four files ship with every preset, they form the universal baseline:

FileapplyToPurpose
architecture-principles**5 questions before coding, 4-layer architecture, separation of concerns
git-workflow**Conventional commits, push reminders, version-aware messaging
ai-plan-hardening-runbookdocs/plans/**Quick-reference when editing plan files
status-reportingdocs/plans/**, .forge/**Standard output templates for orchestration updates

Domain Instruction Files (Per Preset)

Each preset installs 17 domain-specific instruction files. They auto-load based on what you're editing:

FileDomainLoads When Editing
api-patternsREST conventions, pagination, error responsesControllers, routes, endpoints
authJWT/OIDC, RBAC (role-based access control), multi-tenant isolationAuth modules, middleware
cachingRedis, in-memory cache, TTL strategiesCache services, config
databaseORM/query patterns, migrations, connectionsRepositories, SQL, models
daprDapr sidecar patterns, pub/sub, state managementDapr config, service invocation
deployDockerfiles, health checks, container optimizationDockerfiles, compose, k8s
errorhandlingException hierarchy, ProblemDetails (RFC 7807 standard JSON error responses), error boundariesError handlers, middleware
graphqlSchema design, resolvers, query patterns, Hot Chocolate / ApolloGraphQL types, resolvers
messagingPub/sub, job queues, event-driven patternsEvent handlers, message consumers
multi-environmentDev/staging/prod config, environment detectionConfig files, env setup
namingNaming conventions, file organization, namespace rulesAll code files
observabilityOpenTelemetry, structured logging, metricsLogging, tracing, health
performanceHot/cold path analysis, allocation reductionPerformance-critical code
securityInput validation, secret management, CORSAuth, security, middleware
testingUnit tests, integration tests, test containersTest files
versionSemantic versioning, commit-driven bumpsVersion files, changelogs
project-principlesActivates when PROJECT-PRINCIPLES.md existsPlan files, reviews
TypeScript preset adds a 15th file: frontend.instructions.md for React/Vue patterns. The azure-iac preset replaces several app-specific files with Bicep/Terraform equivalents.

Every instruction file includes Temper Guards (shortcut prevention tables) and Warning Signs (observable anti-patterns). These help agents avoid common quality erosion and help reviewers detect violations.

Agents, Skills & Hooks, the reviewer agents (14), slash-command skills (12), and lifecycle hooks are covered in the companion reference: Chapter 10 · Reference — Agents, Skills & Hooks →

📄 Full reference: capabilities, Multi-Agent Setup — GitHub Copilot