How to Make Copilot Remember Your Coding Patterns
How Copilot Uses Context
Copilot generates code suggestions based on the current file, open editor tabs, and any custom instructions configured for the workspace or repository. Unlike Claude Code, which reads a dedicated CLAUDE.md file, Copilot infers patterns from the code it can see in your workspace. This means its suggestions are influenced by the files you have open, the code you have recently written, and the patterns that exist in the surrounding codebase.
Copilot Chat has a broader context scope than inline completions. In chat mode, Copilot can reference files across the workspace, read repository structure, and use custom instructions. Inline completions primarily look at the current file and immediately adjacent context. Understanding this distinction helps you optimize context for each mode.
The fundamental limitation is that Copilot does not carry context between sessions. When you close your editor and reopen it, the slate is clean. Custom instructions persist because they are stored in configuration files, but any conversational context, corrections, or learned preferences from the previous session are gone.
Step-by-Step Setup
Copilot supports custom instructions at the IDE level and at the repository level. IDE-level instructions apply to all your projects and capture personal preferences. Repository-level instructions apply to a specific project and capture team conventions. Start with the repository level, since project-specific context provides the most immediate value.
Create a file at .github/copilot-instructions.md in your repository root. This file is read by Copilot Chat and used as additional context for responses. Write it in natural language with clear, specific instructions.
# Copilot Instructions
## Language and Framework
This is a Go project using the Chi router and GORM ORM.
Use Go 1.22 conventions including range-over-func.
## Code Style
- Use table-driven tests with t.Run() subtests
- Error handling: always wrap errors with fmt.Errorf
and %w verb, never return bare errors
- Naming: use mixedCaps (Go convention), avoid
abbreviations except widely recognized ones (ID, URL, HTTP)
- Struct methods: pointer receivers for methods that
modify state, value receivers for read-only methods
## Architecture
- Handlers receive and validate HTTP input, call services
- Services contain business logic, call repositories
- Repositories handle database access through GORM
- Never call a repository directly from a handler
## Testing
- Unit tests for services use mock repositories (mockgen)
- Integration tests for handlers use httptest.NewServer
- Test files must include both success and error cases
- Use testify/assert, not raw if statementsWhen the file lives in version control, every team member gets the same instructions automatically. Changes to conventions go through pull requests, creating a review process for instruction updates. The file should be updated when team conventions change, just like updating a linting configuration.
Copilot's inline completions are heavily influenced by the files currently open in your editor. When working on a new feature, open an existing file that demonstrates the pattern you want Copilot to follow. If you are adding a new API endpoint, open an existing endpoint file that follows your conventions. Copilot will pattern-match against the open files and generate suggestions that are consistent with the established approach.
This is a manual form of memory that works within a session. The limitation is that you need to remember which files to open, and the technique only works for inline completions, not for chat-based interactions. Still, it is effective for maintaining consistency in the code Copilot generates.
Maintain a set of canonical examples in your codebase that demonstrate your preferred patterns. A well-written reference implementation of your standard CRUD endpoint, your standard database migration, your standard test file, and your standard service class gives Copilot concrete examples to learn from. Place these in a /docs/examples/ directory or in well-commented sections of your actual code.
Reference implementations serve double duty: they guide human developers and influence AI completions. When Copilot sees a consistent pattern repeated across multiple files, it generates suggestions that match that pattern more reliably than when the codebase has inconsistent approaches.
Copilot's extensibility through MCP and GitHub Copilot Extensions enables integration with external memory servers. By connecting an MCP memory server, you give Copilot access to dynamic memory that stores observations from sessions and retrieves relevant context in future conversations. This goes beyond what static instruction files can provide, capturing the evolving knowledge that accumulates as you work with the assistant.
The MCP integration transforms Copilot from a stateless completion engine into a tool that learns your preferences, remembers your corrections, and improves its suggestions based on your history. Combined with the static instruction file, this gives Copilot a comprehensive understanding of your project that rivals what you would get from a well-briefed human colleague.
Limitations and Workarounds
Copilot's memory capabilities are less mature than Claude Code's. It does not natively support the layered file hierarchy that Claude Code uses, and its MCP support is newer and less widely adopted. For teams that rely heavily on persistent memory, Claude Code or Cursor with MCP integrations currently provide a more complete experience.
The workaround for teams committed to Copilot is to invest more in the static instruction file and in codebase consistency. A well-maintained .github/copilot-instructions.md file combined with consistent code patterns across the repository gives Copilot enough context to generate appropriate suggestions. The MCP memory server fills the gap for dynamic, session-to-session knowledge that the static file cannot capture.
Add persistent memory to any AI coding assistant. Adaptive Recall works with Copilot, Claude Code, Cursor, and any MCP-compatible tool through a single memory server.
Get Started Free