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

Podman– Command execution failed with exit code 125

After updating WSL on one of the developer machines, Podman failed to work. When we took a look through Podman Desktop, we noticed that Podman had stopped running and returned the following error message: Error: Command execution failed with exit code 125 Here are the steps we tried to fix the issue: We started by running podman info to get some extra details on what could be wrong: >podman info OS: windows/amd64 provider: wsl version: 5.3.1 Cannot connect to Podman. Please verify your connection to the Linux system using `podman system connection list`, or try `podman machine init` and `podman machine start` to manage a new Linux VM Error: unable to connect to Podman socket: failed to connect: dial tcp 127.0.0.1:2655: connectex: No connection could be made because the target machine actively refused it. That makes sense as the podman VM was not running. Let’s check the VM: >podman machine list NAME         ...

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.

VS Code Planning mode

After the introduction of Plan mode in Visual Studio , it now also found its way into VS Code. Planning mode, or as I like to call it 'Hannibal mode', extends GitHub Copilot's Agent Mode capabilities to handle larger, multi-step coding tasks with a structured approach. Instead of jumping straight into code generation, Planning mode creates a detailed execution plan. If you want more details, have a look at my previous post . Putting plan mode into action VS Code takes a different approach compared to Visual Studio when using plan mode. Instead of a configuration setting that you can activate but have limited control over, planning is available as a separate chat mode/agent: I like this approach better than how Visual Studio does it as you have explicit control when plan mode is activated. Instead of immediately diving into execution, the plan agent creates a plan and asks some follow up questions: You can further edit the plan by clicking on ‘Open in Editor’: ...