GitHub Copilot Prompts & Custom Instructions

GitHub Copilot has evolved far beyond simple autocomplete. With Copilot Chat, custom instructions, and workspace-aware context, it is now a full coding assistant embedded in VS Code and other editors. But most developers are only using a fraction of what Copilot can do. The key to getting better suggestions is understanding how Copilot reads context and how you can shape its behavior with instruction files and prompt techniques.

Copilot supports custom instruction files (`.github/copilot-instructions.md`) at the repository level. These files let you define your project's conventions, preferred libraries, testing patterns, and coding style so Copilot incorporates them into every suggestion. For example, you can specify that your project uses TypeScript strict mode, prefers functional components, and follows a specific naming convention. This eliminates the need to repeat these preferences in every chat interaction and produces dramatically more consistent code.

When using Copilot Chat, specificity matters. Instead of asking "write a function to handle errors," include the expected input types, error cases you want handled, and whether you need try-catch, Result types, or error boundaries. Reference related files with #file mentions so Copilot understands the surrounding code. Browse our Copilot instruction templates and coding prompts to configure Copilot for your codebase and start getting better suggestions immediately.

Copilot Prompts You Can Use Right Now

Copy these inline comments and chat prompts directly into VS Code. Replace the {{variables}} with your specifics.

Inline Generation Comment

// Generate a {{language}} function that {{taskDescription}}
// Input: {{inputType}} — e.g. {{exampleInput}}
// Output: {{outputType}} — e.g. {{exampleOutput}}
// Constraints: {{constraints}}
// Style: use early returns, no nested ternaries
languagetaskDescriptioninputTypeexampleInputoutputTypeexampleOutputconstraints

Why it works: Copilot reads the preceding comment block as context. Specifying input/output types, examples, and style constraints gives the model enough signal to generate correct code on the first try instead of generic boilerplate.

Test Scaffolding Prompt

Write unit tests for the {{functionName}} function in #file:{{filePath}}.

Use {{testFramework}} with the following structure:
- Group tests by behavior (describe blocks)
- Cover: happy path, edge cases (empty input, null, boundary values), and error cases
- Use descriptive test names: "should {{expectedBehavior}} when {{condition}}"
- Mock {{dependenciesToMock}} using {{mockLibrary}}
- Assert both return values and side effects
functionNamefilePathtestFrameworkdependenciesToMockmockLibraryexpectedBehaviorcondition

Why it works: Referencing the exact file with #file gives Copilot Chat the full function signature and dependencies. Specifying the test framework, naming convention, and what to mock prevents generic tests that need heavy editing.

Docstring & JSDoc Generator

Add comprehensive JSDoc documentation to every exported function in #file:{{filePath}}.

For each function include:
- @description — one sentence explaining what it does and why
- @param — each parameter with type and description
- @returns — what is returned and when
- @throws — any errors that can be thrown
- @example — one realistic usage example

Do not modify the function implementations. Preserve existing inline comments.
filePath

Why it works: Constraining Copilot to 'do not modify implementations' prevents accidental code changes. The structured JSDoc format with @example produces documentation that doubles as inline tests for reviewers.

Refactoring Hint Comment

// REFACTOR: Extract the {{logicDescription}} below into a pure function
// called {{newFunctionName}}({{params}}): {{returnType}}
// Move to {{targetFile}}
// Reason: {{reason}}
// Keep the call site here, just replace inline logic with the function call
logicDescriptionnewFunctionNameparamsreturnTypetargetFilereason

Why it works: Copilot's autocomplete engine uses surrounding comments to predict the next edit. This structured refactoring hint tells Copilot exactly where to extract, what to name it, and where to put it — turning a manual refactor into a single Tab accept.

Regex Builder Comment

// Build a regex that matches {{patternDescription}}
// Valid examples: {{validExamples}}
// Invalid examples (should NOT match): {{invalidExamples}}
// Flags: {{flags}}
// Return as a named const with a JSDoc comment explaining the pattern

const {{regexName}}: RegExp = 
patternDescriptionvalidExamplesinvalidExamplesflagsregexName

Why it works: Providing both valid and invalid examples lets Copilot generate a precise regex instead of an overly broad one. Starting the const declaration on the next line triggers inline completion with the full pattern.

API Integration Scaffold

Create a typed API client for the {{apiName}} API in #file:{{filePath}}.

Requirements:
- Base URL: {{baseUrl}}
- Auth: {{authMethod}} ({{authDetails}})
- Endpoints to implement: {{endpoints}}
- Use fetch with proper error handling (throw typed errors)
- Add request/response TypeScript interfaces for each endpoint
- Include retry logic with exponential backoff (max {{maxRetries}} retries)
- Add JSDoc with example usage for each method
apiNamefilePathbaseUrlauthMethodauthDetailsendpointsmaxRetries

Why it works: Copilot Chat generates more accurate API clients when it knows the auth method, base URL, and specific endpoints upfront. Specifying typed errors and retry logic avoids the most common follow-up edits developers make to generated API code.

Copilot Instructions File Template

# .github/copilot-instructions.md

## Project: {{projectName}}
- Language: {{language}} ({{languageVersion}})
- Framework: {{framework}} ({{frameworkVersion}})
- Package manager: {{packageManager}}

## Coding Conventions
- Use {{namingConvention}} for variables and functions
- Prefer {{componentStyle}} components
- Error handling: {{errorHandlingPattern}}
- Always add return types to exported functions

## Testing
- Framework: {{testFramework}}
- File naming: {{testFilePattern}}
- Minimum coverage expectations: {{coverageExpectations}}

## Do NOT
- Use `any` type in TypeScript
- Use default exports (prefer named exports)
- Add comments that restate the code
- Import from relative paths when path aliases exist
projectNamelanguagelanguageVersionframeworkframeworkVersionpackageManagernamingConventioncomponentStyleerrorHandlingPatterntestFrameworktestFilePatterncoverageExpectations

Why it works: This instruction file is loaded by Copilot for every suggestion in the repo. Defining conventions once here means every inline completion and chat response follows your team's standards automatically — no more repeating preferences.

Debug with Copilot Chat

I'm getting this error in #file:{{filePath}} at line {{lineNumber}}:

```
{{errorMessage}}
```

Context:
- This function is called by {{callerDescription}}
- The input data comes from {{dataSource}}
- It worked before {{whatChanged}}

Diagnose the root cause. Explain why it's happening, then provide a fix. If there are multiple possible causes, list them ranked by likelihood.
filePathlineNumbererrorMessagecallerDescriptiondataSourcewhatChanged

Why it works: Giving Copilot the exact error, file reference, caller context, and what changed recently narrows the search space dramatically. Asking for ranked causes prevents the model from fixating on the first plausible explanation.