# AI Context Inclusion Rules
## Rule
When providing context to AI coding tools, follow the priority hierarchy and exclusion rules to maximize signal-to-noise ratio in the context window.
## Priority Hierarchy (Include in This Order)
1. **Type definitions** — interfaces, schemas, enums (highest priority)
2. **Configuration** — tsconfig.json, .eslintrc, package.json
3. **Related implementation** — the file being modified and its direct dependencies
4. **Test files** — existing tests for the code being modified
5. **Examples** — one well-written implementation of the same pattern
6. **Documentation** — relevant README sections or API docs
## Exclusion Rules
### ALWAYS Exclude
```
node_modules/
dist/
build/
.next/
coverage/
*.min.js
*.min.css
*.map
*.lock
.git/
```
### Configure in .cursorignore / .copilotignore
```gitignore
# Build artifacts
dist/
build/
.next/
out/
# Dependencies
node_modules/
.pnpm-store/
# Generated files
*.generated.ts
*.d.ts.map
coverage/
# Large data files
*.csv
*.sql
data/fixtures/
```
## Token Budget Allocation
| Context Type | Budget % | Example |
|-------------|----------|---------|
| Types/Interfaces | 30% | 600 tokens |
| Current file + deps | 40% | 800 tokens |
| Tests/Examples | 20% | 400 tokens |
| Docs/Config | 10% | 200 tokens |
## Good Context Selection
```
# Task: Add new API endpoint for user preferences
Include:
types/user.ts # User and Preference types
api/users/route.ts # Existing pattern to follow
api/users/route.test.ts # Test patterns
lib/db.ts # Database helper signatures
```
## Bad Context Selection
```
# Same task, bad selection
Include:
Everything in src/ # Way too much, most irrelevant
package.json # 500 lines of dependencies
README.md # Generic project description
# Missing: type definitions and existing patterns
```
## Anti-Patterns
- "Just include everything" (context pollution, worse results)
- Missing type definitions (AI invents types)
- Including unrelated files (AI gets confused by irrelevant patterns)
- No .cursorignore configured (generated files pollute suggestions)