Context Files
Cursor Rules and GitHub Copilot
Tool-specific overrides with progressive disclosure and sync patterns
Last verified 2026-09-25
Summary
Tool-specific overrides layered on . Cursor reads AGENTS.md natively (root and nested, closest file wins) and also reads .cursor/rules/*.mdc files for glob-scoped rules; GitHub Copilot reads .github/copilot-instructions.md for repo-wide guidance and .github/instructions/*.instructions.md for path-scoped guidance via applyTo glob frontmatter. Keep tool-specific files minimal, avoid duplication, link to shared conventions in AGENTS.md.
- Cursor: reads
AGENTS.mdnatively (root and nested, closest file wins), with.cursor/rules/*.mdcadding glob-scoped detail on top - Copilot instructions:
.github/copilot-instructions.md(repo-wide) plus.github/instructions/*.instructions.md(path-scoped viaapplyTo) - Copilot coding agent and code review: read
AGENTS.mddirectly (GA 2026) - Glob scoping: apply rules per file pattern in both tools
- Reference AGENTS.md: "See AGENTS.md for project conventions"
- Add tool-only: Cursor/Copilot-specific guidance
- Avoid duplication: don't repeat AGENTS.md content
Cursor reads AGENTS.md directly - root and nested subdirectories, with the closest file to the current context winning - and layers .cursor/rules/*.mdc files on top for glob-scoped detail AGENTS.md doesn't need to carry everywhere. GitHub Copilot reads AGENTS.md directly too, for its coding agent and code review features (GA 2026), and additionally reads .github/copilot-instructions.md (repo-wide) and .github/instructions/*.instructions.md (path-scoped, via applyTo glob frontmatter). Keep all of these thin and focused: reference shared conventions from AGENTS.md, add tool-only guidance.
Cursor Rules (.cursor/rules)
Use .cursor/rules/*.mdc files when you need guidance scoped to a specific glob that doesn't belong in the shared AGENTS.md. Cursor supports multiple rule files scoped by glob patterns. Each file is a .mdc ( Cursor) file that specifies where it applies. The older single-file .cursorrules format is deprecated in Cursor's own docs - migrate it to .cursor/rules/*.mdc or to AGENTS.md.
Structure
---
globs: src/**/*.ts,src/**/*.tsx
---
# Cursor Rules for TypeScript
See AGENTS.md for project conventions.
## TypeScript-Specific Rules
Always:
- Use strict: true in tsconfig
- Define function return types explicitly (no inference)
- Use const for all immutable bindings
- Avoid any; use unknown and narrow
Never:
- Use var
- Use null; prefer undefined
- Use ! non-null assertion without commentThe globs frontmatter tells Cursor when to apply these rules (TypeScript files only).
Glob Patterns
---
globs: src/components/**/*.tsx
---
# React Component Rules
Applies only to React component files.---
globs: "*.test.ts,*.spec.ts"
---
# Test Rules
Applies only to test files.Multi-File Strategy
.cursor/
├── rules/
│ ├── typescript.mdc # TypeScript rules (src/**/*.ts)
│ ├── react.mdc # React-specific (src/**/*.tsx)
│ ├── tests.mdc # Test files (*.test.ts)
│ └── api-routes.mdc # API routes (src/api/**)Each file is focused on a specific . Cursor applies matching rules in order.
Example: Complete Cursor Rules
---
globs: "src/**/*.{ts,tsx}"
---
# TypeScript Project Rules
See AGENTS.md for commands and boundaries.
## Naming
Variables / functions: camelCase
Types / interfaces: PascalCase
Constants: UPPER_SNAKE_CASE (if immutable config)
Files: kebab-case
## TypeScript
Always:
- strict: true (tsconfig.json)
- Explicit return types on exported functions
- Use const for all bindings
- Import types: import type { T } from '...'
Never:
- any type; use unknown and narrow
- null; use undefined
- non-null assertion (!) without comment
- Function expressions; use const fn = () => {}
## Imports
Order:
1. External packages (react, next, zod, etc.)
2. Internal absolute paths (src/...)
3. Relative paths (../)
Example:
import React from 'react';
import { z } from 'zod';
import { useAuth } from 'src/hooks/useAuth';
import { Button } from './Button';
## Comments
Use JSDoc for:
- Public functions and types
- Non-obvious logic
- Why, not what
Avoid:
- Stating the obvious (// increment x)
- Stale comments (update on code change)
## Error Handling
Return errors, don't throw (in tools):
return {
success: false,
error: { code: 'INVALID_INPUT', message: '...' }
};
## Testing
Test file location: src/components/Button.test.tsx (alongside component)
Test structure: describe, it, expectGitHub Copilot Instructions
GitHub Copilot reads .github/copilot-instructions.md for repo-wide guidance. For path-scoped guidance, add .github/instructions/*.instructions.md files with applyTo glob frontmatter - the same idea as Cursor's per-file globs:
---
applyTo: "src/api/**/*.ts"
---
# API Route Instructions
Routes follow RESTful conventions: /api/v1/[resource]/[id]?Structure
# GitHub Copilot Custom Instructions
See AGENTS.md for project conventions and commands.
## Coding Style
- TypeScript with strict mode
- camelCase for functions/variables, PascalCase for types
- Explicit return types on exported functions
- Use const; avoid var and null
## API Design
- RESTful routes: /api/v1/...
- Status codes: 200 (success), 400 (client error), 500 (server error)
- Error responses: { error: { code, message, details } }
## Testing
- Unit tests alongside source files (.test.ts)
- Use Vitest; aim for >80% coverage
- Test behavior, not implementation
## Performance
- Paginate list endpoints (max 50 items)
- Use indexes on frequently queried columns
- Avoid N+1 queries; use batch or joins
## Security
- All API routes require authentication
- Validate input on all endpoints
- Use parameterized queries (Prisma handles this)
- Secrets in .env.local, never in gitTone and Length
Keep GitHub Copilot instructions concise. Copilot's budget is smaller than Claude's or Cursor's. Bullet points beat prose.
# GitHub Copilot Custom Instructions
See AGENTS.md for project conventions.
## Quick Guidelines
- TypeScript strict mode; explicit return types
- camelCase functions, PascalCase types
- REST API: /api/v1/..., status codes 200/400/500
- Test alongside source: Component.test.tsx
- Use const; avoid var and null
- Paginate lists (max 50); validate all inputsThis is ~80 words - tight and actionable.
Keeping Files in Sync
AGENTS.md, CLAUDE.md, Cursor rules, and Copilot instructions can drift. Establish a sync pattern:
Manual Sync Checklist
When AGENTS.md changes, update:
AGENTS.md ← source of truth for commands, boundaries, tech stack
├── CLAUDE.md (optional; starts with `@AGENTS.md` import, add Claude-only hooks)
├── .cursor/rules/ (reference AGENTS.md sections, add Cursor-only rules)
└── .github/copilot-instructions.md (reference AGENTS.md, add Copilot focus areas)Before committing:
- Update AGENTS.md with new commands or boundaries
- If a CLAUDE.md exists, leave its
@AGENTS.mdimport in place - do not restate the change in prose - Update Cursor rules for affected code paths
- Summarize in Copilot instructions (brief version of AGENTS.md)
- Commit all files together
Automated Validation
Add a pre-commit hook to check consistency:
#!/bin/bash
# .git/hooks/pre-commit
# Check that Cursor rules reference AGENTS.md
if grep -r "See AGENTS.md" .cursor/rules/ > /dev/null 2>&1; then
echo "✓ Cursor rules reference AGENTS.md"
else
echo "✗ Cursor rules missing AGENTS.md reference"
exit 1
fi
# Check that Copilot instructions exist if AGENTS.md does
if [ -f "AGENTS.md" ] && [ ! -f ".github/copilot-instructions.md" ]; then
echo "✗ AGENTS.md exists but .github/copilot-instructions.md missing"
exit 1
fi
echo "✓ Context files OK"Project Layout
.
├── AGENTS.md # Universal baseline
├── CLAUDE.md # Claude Code overlay (optional)
├── CONTRIBUTING.md # Detailed contribution guide
├── .cursor/
│ └── rules/
│ ├── typescript.mdc # TS-specific rules
│ ├── react.mdc # React-specific rules
│ └── tests.mdc # Test file rules
├── .github/
│ └── copilot-instructions.md # GitHub Copilot instructions
└── docs/
├── ARCHITECTURE.md # Architecture overview
└── runbooks/ # Deployment, incident responseMonorepo Sync
In monorepos, Cursor rules can be scoped per-package:
.cursor/rules/
├── ts-global.mdc # All .ts files
├── api-routes.mdc # packages/api/src/routes/**
├── web-components.mdc # packages/web/src/components/**
└── tests-global.mdc # All .test.ts filesTop-level .github/copilot-instructions.md applies to all packages.
Example: Full Sync
AGENTS.md:
# AGENTS.md
...
## Testing
Unit: Vitest (pnpm test)CLAUDE.md (importing):
@AGENTS.mdThat single line pulls in the whole AGENTS.md file, Testing section included - nothing to restate. Add Claude-only lines below the import only if Claude needs something no other tool should see.
.cursor/rules/tests.mdc (referencing):
---
globs: "*.test.ts"
---
See AGENTS.md > Testing for test patterns.
## Cursor-Specific Test Rules
Never:
- Use .skip or .only (should not be committed)
- Test implementation; test behavior.github/copilot-instructions.md (summarizing):
# GitHub Copilot Custom Instructions
See AGENTS.md for full conventions.
## Testing
- Tests: src/\*_/_.test.ts (Vitest)
- Run: pnpm test
- Structure: describe, it, expect
- Test behavior, not implementationAll files reference or import AGENTS.md as source of truth. No duplication.
Anti-Patterns
Duplication
# BAD: .cursor/rules/commands.mdc
pnpm dev
pnpm test
pnpm buildAlready in AGENTS.md. Instead:
# GOOD: .cursor/rules/commands.mdc
See AGENTS.md > Quick Start for commands.
This file adds Cursor-specific tips.Stale Content
# BAD: .github/copilot-instructions.md
Use npm install
(But AGENTS.md says pnpm; npm is old.)Sync fails. Use pre-commit hook to prevent this.
Over-Specification
# BAD: Cursor rules
Always:
- Use PascalCase for types
- Use camelCase for functions
- Use const
- Use async/await
- Use arrow functions
- ...30 more rulesToo long. Keep rules focused on non-obvious patterns. AGENTS.md covers the rest.
See also
/docs/context-files/agents-md- AGENTS.md spec/docs/context-files/claude-md- optional Claude Code overlay, only when needed- (Cursor rules docs) - includes AGENTS.md support
- (GitHub Copilot repository instructions) - repo-wide and path-scoped instructions
/templates/discovery/cursor-rules.mdc- starter Cursor rules file/templates/discovery/copilot-instructions.md- starter Copilot instructions