Chapter 9

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 8.)

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
...

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, 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, 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.

As of v2.18, 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

19 agents organized in three categories. Agents are read-only — they audit code but can't edit files.

Stack-Specific Agents (6)

Vary by preset — examples for dotnet:

AgentReviews
architecture-reviewerLayer separation, dependency direction, SOLID
database-reviewerQuery patterns, migrations, connection management
deploy-reviewerDockerfile, health checks, container optimization
performance-reviewerHot paths, allocations, async patterns
security-reviewerInput validation, auth, secrets, OWASP
test-runnerTest coverage, test patterns, mocking strategy

Cross-Stack Agents (8)

Shared across all presets — same expertise regardless of language:

AgentReviews
api-contract-reviewerAPI versioning, backward compatibility, OpenAPI
accessibility-reviewerWCAG 2.2, semantic HTML, ARIA, keyboard nav
multi-tenancy-reviewerTenant isolation, data leakage, RLS, cache separation
cicd-reviewerPipeline safety, secrets, rollback strategies
observability-reviewerStructured logging, distributed tracing, metrics
dependency-reviewerCVEs, outdated packages, license conflicts
compliance-reviewerGDPR, CCPA, SOC2, PII handling, audit logs
error-handling-reviewerException hierarchy, error boundaries, ProblemDetails

Pipeline Agents (6)

Drive the 7-step pipeline with handoff buttons between stages:

AgentPipeline StepWhat It Does
specifierStep 0Interviews you, produces specification
preflightStep 1Verifies prerequisites, checks environment readiness
plan-hardenerStep 2Converts spec into hardened execution contract
executorStep 3Executes slices, validates gates
reviewer-gateStep 5Independent audit for drift and compliance
shipperStep 6Commits, updates roadmap, captures lessons

Skills

12 slash commands per app preset. Skills do work — they can read, write, and run terminal commands:

SkillInvocationWhat It Does
database-migration/database-migrationGenerate, review, test, deploy schema migrations
staging-deploy/staging-deployBuild, push, migrate, deploy, verify on staging
test-sweep/test-sweepRun all test suites and aggregate results
dependency-audit/dependency-auditScan for vulnerabilities, outdated packages, licenses
security-audit/security-auditOWASP scan, secrets detection, severity report
code-review/code-reviewArchitecture, security, testing, patterns review
release-notes/release-notesGenerate from git history and CHANGELOG
api-doc-gen/api-doc-genGenerate/update OpenAPI spec, validate consistency
onboarding/onboardingWalk new dev through setup, architecture, first task
health-check/health-checkForge diagnostic: smith → validate → sweep
forge-execute/forge-executeGuided plan execution: list → estimate → execute → report
forge-troubleshoot/forge-troubleshootDiagnose common Plan Forge issues

Lifecycle Hooks

Hooks run automatically during agent sessions — no manual activation:

HookWhenWhat It Enforces
SessionStartSession beginsInjects Project Principles, current phase, forbidden patterns
PreToolUseBefore file editBlocks edits to paths listed in plan's Forbidden Actions
PostToolUseAfter file editAuto-formats, warns on TODO/FIXME/stub markers
StopSession endsWarns if code modified but no test run detected
PostToolUse warning: If you see "⚠ Deferred-work marker detected" after an edit, the AI left a TODO or stub. Address it before moving on — the completeness sweep (Step 4) will catch it anyway.

📄 Full reference: capabilities.md, COPILOT-VSCODE-GUIDE.md