GitHub Copilot has evolved from a simple autocomplete tool into a full-fledged AI coding assistant. But out of the box, Copilot doesn't know anything about your specific projectβits architecture, naming conventions, or the quirks of your tech stack. To get truly useful suggestions, you need to teach it.
In this guide, we'll walk through practical ways to give Copilot context about your codebase, so its suggestions feel less like generic AI output and more like a teammate who's been on the project for months.
Why Context Matters
By 2026, AI coding assistants have become a standard part of the developer workflow. But a model that only sees the file you're currently editing will often produce code that:
- Ignores your project's existing patterns
- Uses the wrong libraries or APIs
- Breaks style conventions your team relies on
- Misses domain-specific rules (e.g., "never log PII")
The fix is straightforward: feed Copilot the context it needs.
1. Use Custom Instructions
GitHub Copilot supports repository-level custom instructions that are automatically included in its prompts. Adding a file like .github/copilot-instructions.md to your repo lets you describe:
- Project overview: What the app does, who uses it, and its main components
- Tech stack: Languages, frameworks, build tools, and versions
- Coding conventions: Formatting, naming, error handling, and testing patterns
- Do's and don'ts: Security rules, deprecated APIs to avoid, preferred libraries
Even a short, well-written instruction file dramatically improves relevance.
2. Open Relevant Files in Your Editor
Copilot uses the files open in your editor as part of its context window. If you're working on a feature that touches auth.service.ts and user.model.ts, keep those tabs open. Copilot will pick up on existing types, function signatures, and patterns to produce code that fits in.
3. Reference Files with `#` in Chat
In Copilot Chat, you can explicitly reference files by typing # followed by the file name. This is especially useful when:
- The file you need isn't open
- You want Copilot to mirror a specific implementation
- You're asking a question that spans multiple files
Example prompt: "Refactor #payment-processor.ts to match the error-handling pattern used in #order-service.ts."
4. Leverage Workspace and Repository Indexing
Modern GitHub Copilot builds an index of your repository, allowing it to answer questions like "where is the user authentication logic?" or "how are database migrations handled here?" Make sure indexing is enabled in your organization or personal settings, and keep your default branch reasonably up to date so the index reflects reality.
5. Add Domain Knowledge to Comments and Docs
Copilot reads your code comments and markdown files. If your project has a CONTRIBUTING.md, architecture docs, or inline explanations of tricky logic, Copilot can use them as grounding. Write comments that explain why, not just whatβthe model will reward you with smarter suggestions.
6. Iterate with Chat
The fastest way to teach Copilot is through conversation. In Copilot Chat:
- Ask it to explain unfamiliar code
- Point out when a suggestion is wrong and ask for a revised version
- Request that it follow a specific example from your codebase
Over a session, this back-and-forth effectively aligns the model with your project's reality.
A Quick Starter Checklist
- Create
.github/copilot-instructions.mdwith your project's rules - Enable repository indexing in your Copilot settings
- Keep related files open while you work
- Use
#filereferences in chat prompts - Maintain clear comments and architecture docs
Final Thoughts
Copilot is only as good as the context you give it. Treat it like a new team member: onboard it with clear documentation, show it examples, and correct it when it drifts. Do that consistently, and you'll spend far less time fixing AI-generated codeβand far more time shipping features.
Christopher Harrison is a Senior Developer Advocate at GitHub (@geektrainer).
via GitHub AI Blog
