The Prompts Senior Engineers Use to Untangle an AI Codebase
I tested open-ended prompts versus constrained system instructions on a tangled 1,200-line codebase. The open prompt touched 14 files and broke auth; the constrained prompt changed 42 lines cleanly.
01Run this check right now
Diagnostic TestThe Diff Complexity Inspection
Review your last three AI-generated git commits. If single feature prompts touched more than five files across multiple distinct architectural layers, your prompts lack scope boundary constraints.
git diff --stat HEAD~3Findings from the Field
- /01I ran an experiment on a 1,200-line component: an open-ended prompt touched 14 files and broke auth, while a constrained prompt changed 42 lines cleanly.
- /02AI coding models act like talented apprentices: without explicit file boundaries, they take broad speculative shortcuts.
- /03The 'Plan First' constraint forces models to list proposed file edits and wait for approval before modifying code.
- /04How to prompt for surgical component extractions with strictly typed TypeScript interfaces.
- /05Writing a repo-level .cursorrules configuration that permanently enforces modular boundaries.
The 14-file blast radius experiment
When engineers ask me how I use AI coding tools like Cursor, Lovable, or Claude Code, they often expect secret prompt keywords or complex multi-paragraph system prompts.
In reality, effective prompting is about boundary constraints. To see this quantitatively, I took a messy 1,200-line React component from an early prototype and gave the model a common prompt: 'Fix the billing status bug on the customer dashboard.'
The model took the instruction literally and took the shortest path to making the immediate button click work. In doing so, it touched 14 separate files, duplicated two formatting utilities, invented three new global state variables, and silently dropped our token refresh interceptor. The git diff was a disaster.
I rolled back the commit and gave the model the exact same bug using strict boundary constraints. This time, the model modified exactly one file, changed 42 lines of code, and all existing unit tests passed on the first run.
The eager apprentice analogy
Think of it like hiring an enthusiastic junior apprentice carpenter. If you gesture broadly at your house and say: 'Can you renovate the kitchen?', you might come home to find that they have sledgehammered a load-bearing wall, removed your cabinets, and attempted to install an indoor barbecue grill.
If, instead, you say: 'Replace the kitchen sink faucet. Use the standard 3/8-inch brass fitting in drawer number two. Do not touch the subway tile or the shutoff valve underneath', they will execute the job cleanly in twenty minutes.
Template 1: The 'Plan First' constraint
The single most effective constraint you can give an AI assistant is forbidding it from modifying code until it outputs a verifiable plan. This breaks the reflex of speculative editing:
You are acting as a senior staff engineer reviewing this codebase.
Do not modify any files yet.
Task:
Diagnose why customer invoices fail to refresh in src/pages/Billing.tsx.
Requirements:
1. Identify the root cause without speculation.
2. List the exact file paths that must be modified.
3. Propose a minimal fix that reuses existing helpers in src/lib/formatters.ts.
4. Output your plan as a numbered list and wait for my explicit confirmation before touching code.Template 2: The surgical component extraction
When a component grows past 600 lines, asking the AI to 'clean up the file' is asking for hallucinations. Models struggle with large global refactors. Instead, direct surgical, atomic extractions:
Inspect src/pages/CustomerProfile.tsx.
Extract lines 130 to 215 (the PaymentMethodCard section) into a new file:
Path: src/components/profile/PaymentMethodCard.tsx
Constraints:
- The new component must be a pure presentation component.
- All data and callbacks must be passed via a typed interface: PaymentMethodCardProps.
- Do not import Supabase or execute network fetch calls inside this component.
- Import and render the new component inside src/pages/CustomerProfile.tsx.
- Do not modify any other logic or state in the parent file.Template 3: Database query hardening
When prompting for database functions, explicitly enforce multi-tenant isolation and parameterization so the model never generates naive queries:
Write a database query in src/api/invoices.ts to fetch unpaid customer balances.
Constraints:
- Function signature: getUnpaidBalances(orgId: string): Promise<Balance[]>
- Use parameterized SQL to prevent injection.
- Filter by organization_id to enforce multi-tenant security boundaries.
- Join customer details in a single SQL query instead of nested loops.
- Do not use SELECT *. Explicitly list only needed column names.Reflections: codifying rules in .cursorrules
Instead of typing these constraints into every chat prompt, place them in a `.cursorrules` or `CLAUDE.md` file in your repository root. Instruct the model: keep components under 200 lines, do not duplicate existing utilities, require TypeScript strict mode, and never import secret keys into client code.
Prompting is not about poetic phrasing; it is about establishing rigid architectural boundaries. Once the boundaries are set, AI assistants become extraordinary productivity multipliers. Now I am going to brew some tea, because yolo.
Production Hardening & Audits
Stuck on prompt regressions, leaked keys, or database scaling in an AI-built app? Explore our platform-specific teardowns:
Diagnostic & Rescue
1 business day replyThink your prototype is vulnerable or hitting scale limits?
Send us a note with your repository, Supabase link, or project details. A senior engineer will review your policies and reply within one business day.
