In recent years, coding has gained a new collaborator: AI. Tools like GitHub Copilot whisper suggestions as you type, offering code, comments, and even tests. But AI isn’t magic—it’s guided by context. That’s where copilot-instructions.md comes in. Think of it as a handbook for your AI pair programmer. By writing clear instructions, you steer Copilot’s behavior, making it not just helpful but aligned with your team’s standards and philosophy.

This chapter will dive deeply into copilot-instructions.md: why it matters, how to create one, and best practices for maximizing its value. Consider this your manual for training not just humans, but also your AI teammates.


What Is copilot-instructions.md?

It’s a Markdown file you place in your repo to guide GitHub Copilot. It doesn’t change your code—it changes the context Copilot uses to generate suggestions. Think of it as a README for the AI.

Examples of what it might include:

  • Coding conventions (naming, formatting).
  • Preferred libraries and frameworks.
  • Patterns to use or avoid.
  • Project-specific rules (error handling, logging).
  • Examples of “good” and “bad” code.

Visualization:

flowchart TD
  Copilot[GitHub Copilot] --> Reads[copilot-instructions.md]
  Reads --> Suggestions[Aligned Suggestions]

Without it, Copilot guesses. With it, Copilot collaborates.


Why It Matters

AI assistants learn from the world. But your project is not the world—it has unique rules. If you don’t set boundaries, Copilot may generate code that works but violates team standards. By writing instructions, you save time otherwise spent correcting AI outputs.

Benefits:

  • Consistency across team contributions.
  • Faster onboarding for new developers.
  • Reduced cognitive load (AI knows your defaults).
  • Better alignment with testing, CI/CD, and security practices.

Crafting copilot-instructions.md

Start simple. Create a copilot-instructions.md file at the repo root.

Example:

# Copilot Instructions

## Code Style
- Use ESLint rules from `.eslintrc.json`.
- Prefer async/await over callbacks.
- Use `const` and `let`, never `var`.

## Testing
- Always generate Jest tests for new functions.
- Mock external APIs with `nock`.

## Logging
- Use Winston for logging.
- Log errors with `error` level, other messages with `info`.

## Security
- Never commit secrets.
- Sanitize all user input with validator.js.

Now Copilot understands your world.


Adding Examples

AI thrives on examples. Show it what good looks like.

## Examples

### Good
~~~~javascript
async function getUser(id) {
  const user = await db.findById(id);
  if (!user) throw new Error("Not found");
  return user;
}

Bad

function getUser(id) {
  return db.findById(id, function(err, user) {
    if (err) throw err;
    return user;
  });
}

This guides Copilot better than abstract rules.


Best Practices

  1. Keep it concise: too long, and Copilot may ignore parts.
  2. Align with linters: make sure rules match automated checks.
  3. Update regularly: stale instructions mislead.
  4. Include edge cases: tell Copilot what not to do.
  5. Treat it like docs: review in PRs, enforce via code owners.

Solo Workflow Example

As a solo dev, you use copilot-instructions.md to remind AI of your quirks. For instance, always use black for Python formatting. Copilot respects your style, saving micro-corrections.


Team Workflow Example

On a team, instructions enforce consistency. One developer might prefer callbacks, another promises—but the file says “async/await only.” Copilot aligns everyone, silently enforcing standards.

Visualization of team alignment:

flowchart LR
  DevA[Dev A] --> Copilot[Copilot with Instructions]
  DevB[Dev B] --> Copilot
  Copilot --> Unified[Consistent Codebase]

Advanced Strategies

  • Project philosophy: Include mindset, not just syntax. Example: “Prefer functional patterns over OOP.”
  • Error handling: Tell Copilot to always wrap DB calls in try/catch.
  • Security: Explicitly forbid unsafe APIs.
  • Documentation: Ask Copilot to always generate docstrings.

Think Different Mindset

copilot-instructions.md isn’t about controlling AI—it’s about teaching it to think with you. Git taught us history matters. CI/CD taught us automation matters. Now Copilot teaches us alignment matters. By documenting our philosophy, we shape not just human collaboration but human-AI collaboration.


Copilot is powerful, but without guidance, it’s generic. With copilot-instructions.md, you transform it into a teammate who codes like you want. Treat the file as living documentation, evolve it with the project, and you’ll find Copilot becomes less a tool and more a true collaborator. In the next chapter, we’ll expand to best practices and checklists for Git mastery overall.