GitHub Copilot: Three Ways to Get Better Code Suggestions

GitHub’s monthly Insider newsletter now picks one product per issue and goes deep on how to get the most out of it. The latest edition focuses on GitHub Copilot, which is timely: a GitHub survey found that 92% of developers already use AI coding tools in some capacity. Below are the prompting strategies from that guide, condensed for quick reference.

Once Copilot is installed in your IDE, the way you phrase your requests has a big impact on the suggestions you receive. These three approaches cover the most common scenarios.

1. Start Big, Then Let It Fill In Details

When you’re facing a blank file or a fresh codebase, begin with a high-level goal. A comment that describes what you want to build—at a broad level—gives the AI context before you dive into specifics.

/* Create a basic markdown editor in Next.js with the following features:
- Use react hooks
- Create state for markdown with default text "type markdown here"
- A text area where users can write markdown - Show a live preview of the markdown text as I type
- Support for basic markdown syntax like headers, bold, italics - Use React markdown npm package
- The markdown text and resulting HTML should be saved in the component's state and updated in real time */

In testing, a detailed comment of this sort prompted Copilot to generate a simple, unstyled but functional markdown editor in under 30 seconds. Since generative AI outputs are non-deterministic, the exact responses will vary from run to run.

An animated image of the GitHub Copilot interface.

2. Break It Into Simple, Specific Steps

For more complex tasks, keep each instruction focused on a single small step. Shorter, clear prompts produce shorter but more accurate code. Let Copilot generate code after each step rather than asking for an entire routine at once—think of it as giving a recipe with one instruction per line instead of a paragraph that describes the final dish.

3. Include an Example: It Teaches Better Than a Description

Copilot learns from examples just as well as humans do. Consider a task to extract names from an array and store them in a new array. A prompt with no sample input and output tends to produce an incorrect map usage:

// Map through an array of arrays of objects to transform data
const data = [
[
{ name: 'John', age: 25 },
{ name: 'Jane', age: 30 }
],
[
{ name: 'Bob', age: 40 }
]
];

Add a short example to the same prompt, however, and the model converges on the intended behavior:

// Map through an array of arrays of objects
// Example: Extract names from the data array
// Desired outcome: ['John', 'Jane', 'Bob']
const data = [
[{ name: 'John', age: 25 }, { name: 'Jane', age: 30 }],
[{ name: 'Bob', age: 40 }]
];

Which yields the correct result:

const mappedData = data.flatMap(sublist => sublist.map(person => person.name));

console.log(mappedData);
// Results: ['John', 'Jane', 'Bob']

Refining Your Prompts from Vague to Precise

If a response misses the mark, don’t settle—redraft the prompt to add boundaries and clarify input and output. These three versions of the same logical request show the progression:

# Write some code for grades.py

The first version is too loose: no context and no guardrails, so Copilot can’t determine relevance.

# Implement a function in grades.py to calculate the average grade

This revision is sharper, but it still omits what goes in and what should come out.

# Implement the function calculate_average_grade in grades.py that takes a list of grades as input and returns the average grade as a floating-point number

The third attempt draws clear boundaries, states the function’s purpose, and rephrases the request to give Copilot an explicit criterion to verify against.

Open Context Tabs Help Copilot “See” More of Your Work

Copilot uses a technique the GitHub team calls neighboring tabs: it processes the files you have open in the IDE, not just your active file, to build more relevant context. There’s no magic number of tabs—from GitHub’s own experience, one or two extra related files is enough.

If you want a hands-on project to test these techniques, GitHub previously published a seven-step tutorial for building a browser extension that clears your cache, written specifically around Copilot usage.