Skip to main content

Let GitHub Copilot create custom instructions based on your codebase

If you are not using custom instructions with GitHub Copilot, than this post will maybe help to finally get started. Writing your own set of custom instructions can be a challenge and although multiple examples are available, it still can be a challenge coming up with the right set of instructions.

But what if we can let GitHub Copilot create the instructions for us? Let’s find out how…

Why custom instructions?

Custom instructions in GitHub Copilot can significantly improve your coding experience and productivity in several key ways:

  • Code quality and consistency Custom instructions help ensure Copilot generates code that follows your specific style guidelines, naming conventions, and architectural patterns. Instead of getting generic suggestions, you'll receive code that matches your project's existing standards and practices.
  • Context awareness By providing instructions about your tech stack, frameworks, and project structure, Copilot can make more relevant suggestions. For example, telling it you're using TypeScript with React and specific libraries will result in more accurate completions.
  • Reduced manual editing Well-crafted instructions mean less time spent modifying Copilot's suggestions. The AI will generate code closer to what you actually need, reducing the back-and-forth of tweaking suggestions to fit your requirements.
  • Domain-specific knowledge If you work in specialized domains (healthcare, finance, government), custom instructions can incorporate industry-specific practices, compliance requirements, or domain terminology that generic AI responses might miss.
  • Personal preferences You can specify preferences for things like error handling patterns, logging approaches, testing methodologies, or even whether you prefer functional or object-oriented programming styles.
  • Project-specific context Instructions can include information about your current project's goals, constraints, or unique requirements that would be impossible for Copilot to infer from code alone.

The time invested in setting up thoughtful custom instructions typically pays off quickly through more accurate, useful, and immediately applicable code suggestions.

Let GitHub Copilot create custom instructions

To generate custom instructions, you need to take the following steps:

  • Open your solution or project in VS Code
  • Click on to the Settings icon above the GitHub Copilot Chat window:

  • Select Generate Instructions from the context menu:

 

  • Copilot generates the following prompt and starts working on it:

Analyze this codebase to generate or update `.github/copilot-instructions.md` for guiding AI coding agents.

Focus on discovering the essential knowledge that would help an AI agents be immediately productive in this codebase. Consider aspects like:
- The "big picture" architecture that requires reading multiple files to understand - major components, service boundaries, data flows, and the "why" behind structural decisions
- Critical developer workflows (builds, tests, debugging) especially commands that aren't obvious from file inspection alone
- Project-specific conventions and patterns that differ from common practices
- Integration points, external dependencies, and cross-component communication patterns

Source existing AI conventions from `**/{.github/copilot-instructions.md,AGENT.md,AGENTS.md,CLAUDE.md,.cursorrules,.windsurfrules,.clinerules,.cursor/rules/**,.windsurf/rules/**,.clinerules/**,README.md}` (do one glob search).

Guidelines (read more at https://aka.ms/vscode-instructions-docs):
- If `.github/copilot-instructions.md` exists, merge intelligently - preserve valuable content while updating outdated sections
- Write concise, actionable instructions (~20-50 lines) using markdown structure
- Include specific examples from the codebase when describing patterns
- Avoid generic advice ("write tests", "handle errors") - focus on THIS project's specific approaches
- Document only discoverable patterns, not aspirational practices
- Reference key files/directories that exemplify important patterns

Update `.github/copilot-instructions.md` for the user, then ask for feedback on any unclear or incomplete sections to iterate.

  • After analyzing the codebase, you get your instructions file. Don't forget to review and tweak it further.

 

  • Thank you Copilot!

More information

Configure custom instructions for GitHub Copilot - GitHub Docs

GitHub Copilot - Custom Instructions

Finding inspiration for good custom instructions for GitHub Copilot

Custom instructions when using GitHub Copilot

Context is key–Add instructions to your copilot-instructions.md file

Popular posts from this blog

Kubernetes–Limit your environmental impact

Reducing the carbon footprint and CO2 emission of our (cloud) workloads, is a responsibility of all of us. If you are running a Kubernetes cluster, have a look at Kube-Green . kube-green is a simple Kubernetes operator that automatically shuts down (some of) your pods when you don't need them. A single pod produces about 11 Kg CO2eq per year( here the calculation). Reason enough to give it a try! Installing kube-green in your cluster The easiest way to install the operator in your cluster is through kubectl. We first need to install a cert-manager: kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.14.5/cert-manager.yaml Remark: Wait a minute before you continue as it can take some time before the cert-manager is up & running inside your cluster. Now we can install the kube-green operator: kubectl apply -f https://github.com/kube-green/kube-green/releases/latest/download/kube-green.yaml Now in the namespace where we want t...

Azure DevOps/ GitHub emoji

I’m really bad at remembering emoji’s. So here is cheat sheet with all emoji’s that can be used in tools that support the github emoji markdown markup: All credits go to rcaviers who created this list.

DevToys–A swiss army knife for developers

As a developer there are a lot of small tasks you need to do as part of your coding, debugging and testing activities.  DevToys is an offline windows app that tries to help you with these tasks. Instead of using different websites you get a fully offline experience offering help for a large list of tasks. Many tools are available. Here is the current list: Converters JSON <> YAML Timestamp Number Base Cron Parser Encoders / Decoders HTML URL Base64 Text & Image GZip JWT Decoder Formatters JSON SQL XML Generators Hash (MD5, SHA1, SHA256, SHA512) UUID 1 and 4 Lorem Ipsum Checksum Text Escape / Unescape Inspector & Case Converter Regex Tester Text Comparer XML Validator Markdown Preview Graphic Col...