Coding Prompts & Project Instructions
System Prompt Architecture
[ROLE] - Expert persona definition
[CONSTRAINTS] - Scope limitations (lazy vs overeager)
[CONTEXT] - How files are provided and trusted
[OUTPUT FORMAT] - Exact format for responses
[EXAMPLES] - Worked interaction demonstrating behavior
[REMINDERS] - Critical constraints restated near end
Two Constraint Patterns
Lazy Pattern (ensure completeness)
"You are diligent and tireless! You NEVER leave comments describing code without implementing it! You always COMPLETELY IMPLEMENT the needed code!"
Overeager Pattern (prevent scope creep)
"Pay careful attention to the scope of the user's request. Do what they ask, but no more. Do not improve, comment, fix or modify unrelated parts of the code in any way!"
Production System Prompts (Aider)
| Mode | Output Format | Key Instruction |
|---|---|---|
| EditBlock | SEARCH/REPLACE blocks | "Every SEARCH must EXACTLY MATCH existing content" |
| Architect | Natural language plan | "Provide direction to your editor engineer" |
| WholeFile | Complete file content | "NEVER skip, omit or elide content" |
| UDiff | diff -U0 format |
"Replace entire functions when editing" |
| Ask | Q&A only | "Answer questions, don't edit files" |
Project Instruction Files
Cross-Tool Comparison
| Tool | File | Location | Format |
|---|---|---|---|
| Claude Code | CLAUDE.md |
Project root | Markdown |
| Cursor | .cursor/rules/*.mdc |
.cursor/rules/ |
MDC + YAML |
| Copilot | copilot-instructions.md |
.github/ |
Markdown |
| Windsurf | .windsurfrules |
Project root | Markdown |
| Aider | CONVENTIONS.md |
Project root | Markdown |
| Cline | .clinerules |
Project root | Plain text |
| Gemini CLI | GEMINI.md |
.gemini/ |
Markdown |
Universal Template
## Stack
- Language: TypeScript 5.x strict mode
- Framework: React 19 + Next.js 15
- Styling: Tailwind CSS + shadcn/ui
- Database: PostgreSQL + Drizzle ORM
- Testing: Vitest + Playwright
## Conventions
- Functional components with hooks
- Named exports over default exports
- Explicit return types on all functions
- Zod for runtime validation
- Error boundaries for React components
## File Organization
- Components: src/components/{feature}/
- Services: src/services/
- Types: src/types/
- Tests: co-located (foo.test.ts)
## Git
- Conventional commits (feat:, fix:, refactor:)
- PR must include Summary + Test Plan
- No force push to main
## Boundaries
- Never modify migration files
- Never commit .env files
- Always run tests before suggesting completion
Chain-of-Thought for Code
Zero-Shot CoT
Append "Let's think step by step" — improves accuracy from 18% to 79%.
Plan-Then-Code
Before writing code:
1. Analyze requirements
2. Identify edge cases
3. Plan architecture
4. Write pseudocode
5. Implement
6. Verify against requirements
Bug Fix CoT
1. Read error message, identify symptom
2. Trace code path to error
3. Identify root cause (not just symptom)
4. Consider regression risk
5. Propose minimal fix
Few-Shot Patterns
Code Generation
Show 2-3 examples with: input description → typed function with docstring + error handling → tests.
Test Generation
Show existing function → comprehensive tests (happy path, edge cases, error cases).
Bug Fix
Show buggy code → analysis (symptom, root cause) → minimal fix.
Refactoring
Show before → after with explanation of changes.
Key finding (Min et al.): Format consistency matters more than label correctness. 2-5 examples is the sweet spot.
Context Management
Aider's PageRank Repo Map
- tree-sitter extracts definitions + references
- NetworkX builds cross-file dependency graph
- PageRank ranks file importance
- Binary search fits optimal tag count to token budget
Strategy by Context Distance
| Distance | Strategy |
|---|---|
| Active file | Full content |
| Referenced files | Function signatures |
| Distant files | Names only |
Structured Output
Instructor Pattern (Pydantic)
class CodeReview(BaseModel):
file: str
issues: list[Issue]
severity: Literal["low", "medium", "high", "critical"]
review = client.chat.completions.create(
model="gpt-4", response_model=CodeReview,
messages=[{"role": "user", "content": f"Review:\n{code}"}]
)
ReAct Pattern
Thought: I need to understand the file structure
Action: list_files(path="src/")
Observation: [main.py, utils.py]
Thought: Bug likely in utils.py
Action: read_file(path="src/utils.py")