Public EcoRouter Knowledge · AI-generated content ·
How do I prompt an AI coder to fix one bug without rewriting unrelated files, and what context should I paste in?
The question
How do I prompt an AI coder to fix one bug without rewriting unrelated files, and what context should I paste in?
To ensure an AI coder focuses only on the specific bug without refactoring your entire codebase, you need to use a "surgical" prompting approach. Here is how to structure your request:
1. The "Containment" Prompt
Start by explicitly defining the boundaries of the task.
- The Constraint: Add a directive like: "Please provide a fix for [specific issue] only. Do not modify, refactor, or output code for any files other than [Filename]. Do not suggest changes to architecture or surrounding logic unless strictly necessary to resolve this specific bug."
- The Format: Ask for the output in a specific format, such as a unified diff or a "Find and Replace" block. This prevents the AI from regenerating the entire file.
2. What Context to Provide
Providing too little context leads to hallucinations; providing too much leads to "model drift" where the AI loses focus. Include only these four elements:
- The Error Message/Symptom: Provide the exact stack trace, error log, or a clear description of the unexpected behavior.
- The Target File: Paste only the contents of the specific file containing the bug.
- Relevant Dependencies: If the bug involves how one file interacts with another, include only the interface or function signatures of the related file (e.g., the function definitions being called), not the implementation of the secondary file.
- The Goal: A one-sentence summary of the desired state (e.g., "The function should return
nullinstead of throwing an error when the input array is empty").
3. Workflow Tips
- Use a "Context Window" Strategy: If your file is very large, don’t paste the whole thing. Paste the relevant function or class block that is failing, plus the imports at the top.
- Ask for Validation: Instead of asking the AI to "fix it," ask it to "identify the root cause and propose a minimal code change to resolve it." This forces the model to perform an analysis step before it starts writing code.
- Review Before Applying: If you are using an IDE integration (like Cursor or Copilot), look at the "diff" view carefully. If the AI suggests changes to multiple files, reject those specific hunks and only accept the ones pertaining to your target file.
Example Prompt Template:
"I have a bug in
auth.jswhere thevalidateTokenfunction fails if the header is missing.Here is
auth.js: [Paste Code]Please provide a fix only for this file. Do not rewrite any other files. If you need to change the function logic, keep it as minimal as possible. Please output the solution as a code block showing the specific lines to be changed."
Answering this used an estimated 90% less than EcoRouter’s configured frontier baseline
- Routed to
- Efficient
- Tokens
- 396 in / 613 out
- Cost
- $0.0010
- Baseline
- $0.01
Figures recorded by EcoRouter when this answer was generated, and fixed at that moment. Cost comparisons are against a configured reference model, not a measurement of electricity, carbon or water.
Ask about this
Ask EcoRouter a follow-up using this Knowledge as context. Nothing becomes public unless you choose to publish it.
Ask a follow-upComments
No comments yet.