AD SPACE AVAILABLE · BRAND PARTNERS WELCOME

Configuring Custom Instructions and Workspace Context in GitHub Copilot for VS Code

Charmaine Ng · 365Finds Editorial
Indexed 88,650 Wiki articles

Put 365 Wiki to work with your AI

Copy the prompt below, paste it into the AI you already use, then ask your question.

Download full Skill

Try it with the prompt first. If you use 365 Wiki often, install the full 365Wiki Skill so you do not have to paste it again. No regular AI? Gemini or Microsoft Copilot on the web will work.

365Wiki Skill

Out of the box, GitHub Copilot behaves like a talented junior engineer with severe amnesia. It knows the syntax of twenty programming languages, but it does not know that your project banned Axios six months ago in favor of native fetch, that your state management runs strictly on Zustand, or that database queries must never leave the repository layer. Left unguided, it suggests whatever pattern was most prevalent across open-source repositories in 2022.

At 365Finds, we consider configuring custom instructions and workspace context the dividing line between an AI tool that accelerates engineering and an unpredictable autocomplete engine that generates subtle technical debt. You do not need complex external prompt-management frameworks to fix this. Visual Studio Code and GitHub Copilot offer native mechanisms designed specifically to anchor the model to your codebase.


1. Repository-Level Custom Instructions: .github/copilot-instructions.md

The most reliable, team-wide way to steer GitHub Copilot in VS Code is the repository-level instruction file. When present at the root of a repository, GitHub Copilot Chat automatically incorporates its contents into the prompt context for all contributors working in that workspace.

File Placement

Create the file at the exact path below:

your-project-root/
└── .github/
    └── copilot-instructions.md

What to Put Inside

Copilot reads this file as a persistent system brief. Keep it structured, imperative, and concise. Do not write polite paragraphs; provide concrete boundaries.

# Project Architectural Guidelines

## Core Tech Stack & Versions
- Node.js 22 LTS, TypeScript 5.5+ (strict mode enabled).
- Framework: Next.js 15 (App Router only; do not use Pages Router conventions).
- State: Zustand for client store; Server Actions for data mutations.
- Styling: Tailwind CSS v4. No CSS modules or inline style objects.

## Architectural Boundaries
- Keep all database access strictly inside `src/server/db/repositories/`.
- Never import server-only database clients into files under `src/components/`.
- Validate all incoming API request payloads with Zod schemas defined in `src/schemas/`.

## Testing & Quality Rules
- Write tests using Vitest and React Testing Library.
- Mock network calls with MSW (Mock Service Worker). Avoid manual `vi.spyOn(global, 'fetch')`.
- All exported functions must have concise TSDoc comments covering parameter contracts.

When you query Copilot Chat in VS Code, the extension automatically injects these rules into the background context. You can verify this in the chat interface by expanding the Used references dropdown at the top of the assistant's reply; .github/copilot-instructions.md will appear when relevant.


2. Granular and User-Level Configurations

A single repository-wide file is not always enough. A mono-repo might contain a Python data pipeline and a React frontend with diametrically opposed conventions. VS Code provides two complementary ways to scope instructions.

Modular Instruction Files (.instructions.md)

VS Code supports path-scoped and modular instructions located in .github/instructions/:

.github/
└── instructions/
    ├── frontend.instructions.md
    └── testing.instructions.md

You can manage and discover these through the Agent Customizations editor:

  1. Open the Command Palette (Ctrl+Shift+P on Windows/Linux, Cmd+Shift+P on macOS).
  2. Run Chat: Open Customizations.
  3. Select the Instructions tab to view, enable, or create targeted instruction files for the workspace.

Settings-Based Instructions (settings.json)

If you want personal instructions that apply across all your workspaces without committing files to a shared Git repo, configure them in your VS Code settings.json (User level) or .vscode/settings.json (Workspace level):

{
  "github.copilot.chat.codeGeneration.instructions": [
    {
      "text": "Always prefer early returns over deeply nested if-else blocks."
    },
    {
      "file": "./docs/architecture-decisions.md"
    }
  ],
  "github.copilot.chat.testGeneration.instructions": [
    {
      "text": "Generate test cases covering edge cases: empty arrays, null values, and network timeout errors."
    }
  ],
  "github.copilot.chat.commitMessageGeneration.instructions": [
    {
      "text": "Follow Conventional Commits format (e.g., feat(auth): add token refresh handler)."
    }
  ]
}

Notice that VS Code separates instructions by intent: code generation, test generation, and commit message creation can each receive dedicated guidance.


3. Controlling Workspace Context in VS Code

Custom instructions define the rules; workspace context supplies the facts. A common developer frustration is asking Copilot a question about a function, only for Copilot to guess how that function was implemented instead of reading it.

GitHub Copilot does not hold your entire multi-gigabyte project in active memory. It relies on dynamic retrieval, workspace indexing, and explicit user targeting.

Explicit Mentions: #file and #selection

The fastest way to guarantee context accuracy is to feed Copilot explicit references rather than expecting semantic search to guess correctly:

In everyday development, 365Finds recommends prompting with targeted references:

@workspace /explain how #file:src/auth/session.ts handles expired JWTs compared to #file:src/auth/middleware.ts

The Workspace Index and Pruning Context

VS Code automatically indexes workspace files in the background to enable semantic search for @workspace queries. However, poor repository hygiene severely degrades context quality. If Copilot crawls generated build files, minified bundles, or mock fixtures, it consumes context budget on irrelevant tokens.

To keep Copilot's workspace context lean:

  1. Leverage standard ignore files: Copilot respects .gitignore. Ensure node_modules, dist/, .next/, and generated coverage reports are ignored.
  2. Configure VS Code exclusions: Check files.exclude and search.exclude in .vscode/settings.json. Excluding third-party vendor directories prevents the semantic indexer from polluting search results.

4. 365Finds Rules for Production Instruction Design

Writing instructions for an LLM requires discipline. Long, rambling instruction files lead to instruction drift, where the model ignores earlier rules in favor of later ones, or burns tokens that could have been used for code reasoning. 365Finds applies four guidelines across internal engineering projects:

RuleRationaleAnti-Pattern
Enforce negative constraintsLLMs default to generic patterns unless forbidden.Saying "Write modern code" instead of "Do not use axios; use fetch".
Keep under 150 linesInstruction files share the system prompt token window.Dumping a 600-line corporate handbook into markdown.
Offload style to lintersNever waste prompt tokens on semicolons or indentation.Writing rules for things Biome, Prettier, or ESLint autofix.
Pin versions explicitlyPrevents Copilot from writing code for superseded major versions.Saying "Use Next.js" instead of "Next.js 15 App Router".

Configuring these settings takes less than twenty minutes per repository. Once committed, GitHub Copilot stops proposing patterns from obsolete frameworks and begins working within the architectural boundaries of your actual system.

References