To improve outcomes with Copilot for code edits, focus on how prompts are structured, how much work is requested at once, and how results are reviewed.
- Limit each request to a small, single change
- Ask Copilot for “one commit’s worth of changes at a time.”
- Break work into narrow tasks such as:
- “Rename this method and update all its call sites.”
- “Add a null-check before this line and return early.”
- Smaller, focused edits reduce the chance of truncated code or unrelated changes.
- Be very specific and granular in prompts
- Clearly describe the scope and location of the change:
- Reference the exact file, function, or region.
- Describe what must not change (for example, “do not modify any logging statements” or “do not change method signatures”).
- Use simple, direct language and keep the description to a single topic. Granular instructions and a limited scope help Copilot stay precise.
- Provide context explicitly
- When using tools like GitHub Copilot Chat or Copilot Edits in Visual Studio, reference the relevant files or solution as context so Copilot sees the right code.
- If available, use features that let the prompt reference specific files, symbols, or errors. This reduces the risk of Copilot inventing non-existent lines or insertion points.
- Use edit sessions and review diffs carefully
- Start an edit session (for example, a Copilot Edits thread) focused on the specific change.
- After Copilot proposes changes:
- Open each file and review the diff.
- Accept or reject suggestions chunk by chunk rather than all at once.
- Reject any fragment that refers to lines that do not exist or that truncates code.
- Only commit after verifying that the code compiles and tests pass.
- Keep instructions clear and concise
- Avoid very long, multi-part prompts. Complex, verbose instructions are harder for Copilot to follow accurately.
- If the result is off, re-run with a refined, more precise prompt instead of continuing in a confused thread.
- Start fresh when the session drifts
- If Copilot starts ignoring constraints or producing inconsistent output, start a new topic or new edit session.
- Restate the constraints and the exact change needed in the new session.
- Provide feedback on bad outputs
- Use thumbs up/down or built-in feedback options when Copilot truncates code, invents lines, or breaks workflows.
- Feedback is used to improve quality and filtering over time.
- Treat Copilot output as a draft, not final code
- Always review generated code for correctness, completeness, and adherence to constraints.
- Validate behavior with tests or manual checks before relying on the change.
These practices align with recommended operational factors for effective and responsible Copilot use: granular, single-topic prompts; clear, specific instructions; small, reviewable change sets; and careful review of generated content.
References: