Skip to content

CLI should load .github/ selectively, not bulk-load all files into context #2544

@jacob-schmier-sndk

Description

@jacob-schmier-sndk

Problem

When .github/ is not gitignored, Copilot CLI includes all files from .github/ in the initial context payload without selective filtering — treating them as general repository content rather than structured AI guidance artifacts. VS Code Copilot handles the same directory correctly by loading content selectively (only what's relevant to the current task).

This creates an impossible choice for teams that maintain AI guidance artifacts in .github/:

  • Un-ignore .github/ → CLI context explodes, leaving almost no room for actual work
  • Keep .github/ gitignored → CLI works, but instructions and skills that should be available are invisible

Root Cause

The CLI lacks selective loading logic for .github/ content. VS Code implements staged loading (instructions scoped by glob, skills loaded on demand); the CLI does not — it includes all non-ignored files as undifferentiated context.

Trigger (verified)

Two .gitignore lines that un-ignore .github/ expose the missing feature:

!.github/
!.github/**

Adding only these two lines to a working repo's .gitignore reproduces the issue. Removing them resolves it. No other file changes are involved.

Evidence

Isolated via binary search on a large monorepo. The only variable is the .gitignore change above — no other file differences.

Representative magnitude (illustrative, based on observed behavior in a real monorepo):

Configuration Context tokens
.github/ gitignored (baseline) ~60k
.github/ un-ignored via !.github/ ~220k
Un-ignored, then !.github/ lines removed ~60k
Baseline + only !.github/ lines added ~220k

A .github/ directory with a few hundred files of AI guidance artifacts (instructions, skills, agents, prompts, standards, reference docs) can easily add 150k+ tokens to the CLI context. The structure follows documented conventions:

  • copilot-instructions.md (repo-wide instructions)
  • instructions/*.instructions.md (path-scoped, with applyTo globs)
  • skills/*/SKILL.md (on-demand skill files with references/ subdirectories)
  • agents/*.md, prompts/*.md, hooks/*.py, standards/*.md

VS Code Behavior (documented, correct)

VS Code Copilot loads .github/ content selectively, per official documentation:

Custom Instructions (VS Code Docs, GitHub Docs):

  1. Always loaded: copilot-instructions.md (repo-wide)
  2. Loaded when editing matching files: instructions/*.instructions.md based on applyTo metadata (a glob pattern specifying which file paths the instruction applies to)

Agent Skills (VS Code Docs, Microsoft Learn, Progressive Disclosure Pattern):

Skills use a staged loading model ("progressive disclosure" — load only what's needed, when it's needed):
3. Startup: Only metadata (name + description from YAML header) is scanned for discovery (~50-100 tokens per skill)
4. On match: Full SKILL.md body loaded only when the skill is invoked
5. On need: references/, scripts/ loaded only when the skill explicitly requests them

Never bulk-loaded: standards/, hooks/, and other supporting content

This staged loading keeps context usage proportional to the task at hand.

CLI Behavior (current)

CLI treats un-ignored .github/ files as general repository content and includes all of them in the initial context payload. There is no differentiation between:

  • Instruction files that should be auto-loaded
  • Skill files that should be loaded on demand
  • Reference/standards docs that should only be loaded when a skill requests them

Requested Behavior

Copilot CLI should implement the same selective loading strategy as VS Code:

  1. Auto-load copilot-instructions.md (already works when visible)
  2. Scope-load instructions/*.instructions.md based on applyTo metadata and current working context (using the same glob syntax VS Code accepts)
  3. On-demand load skills/*/SKILL.md only when a skill is invoked (CLI already has skill invocation support)
  4. Exclude from bulk context references/, standards/, hooks/, and other supporting files unless explicitly requested

This would allow teams to un-ignore .github/ for git tracking without overwhelming the CLI context window.

Workarounds Considered (all insufficient)

Workaround Why it fails
.copilotignore to exclude .github/ subdirs Binary — hides content completely, prevents on-demand loading
Keep .github/ gitignored Instruction files in instructions/ don't load (see #713)
respectGitignore: false Opposite direction — would expose even more ignored files
Work from subdirectory Doesn't help — .github/ is at repo root

Environment

  • Copilot CLI version: 1.0.19
  • OS: Windows 11
  • Repo type: Large monorepo with extensive .github/ AI guidance artifacts

Related Issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions