Skip to main content
rule official · GitHub

context7 — GitHub Copilot rule: use and install

This rule brings Context7 into tasks that depend on current, version-specific API documentation. It is useful when the workspace does not contain the needed external reference.

Install into GitHub Copilot · Manually: put the files in place All methods and platforms ↓
.github/instructions/context7.instructions.md
Open on GitHub

What context7 does

The rule applies to every file through applyTo: '**'. It tells the agent to use Context7 when local context is not enough for library APIs, version changes, configuration, security-sensitive patterns, third-party errors, or API constraints. Local refactors, formatting, naming, and language fundamentals do not need it.

When a library ID is supplied, the rule uses it directly. Otherwise, the workflow starts with resolve-library-id, continues with query-docs, and only then produces code or implementation steps. It favors primary sources, asks the agent to cite a source title and URL when external facts affect the decision, and calls for a validation step when values or assumptions matter.

For version-dependent work, this rule means documentation is checked before code changes are written. When Context7 is available as an MCP server, each question allows up to 3 calls to resolve-library-id and up to 3 calls to query-docs. API keys must not be requested or echoed; configuration should use environment variables.

What it helps with

  • verify a library method signature
  • check configuration for a named framework version
  • interpret an error from a third-party tool
  • confirm API limits, headers, or supported formats

Example prompts for the agent

  • Use Context7 to verify the API for the library version in this project, then suggest the code change.
  • Check the official docs before configuring authentication and give me the exact configuration values.
  • Look up this third-party tool error in current documentation and add a short validation step.

How to install context7

Manually: put the files in place

.github/instructions/context7.instructions.md

The applyTo field sets which files it applies to

Step by step, with commands for each platform: AGENTS.md vs CLAUDE.md: what they are and which one to use

Questions about context7

How do I install context7 in GitHub Copilot?

Add the rule file at .github/instructions/context7.instructions.md.

What does context7 do?

It tells GitHub Copilot to consult Context7 for current external documentation when the workspace context is insufficient. The rule covers library lookup, documentation retrieval, and applying the findings to code.

When should context7 be skipped?

Skip it for local refactors, formatting, naming, and logic that can be derived from the repository. It is also unnecessary for language fundamentals that do not involve external APIs.

Source text

context7.instructions.md · MIT
---
description: 'Use Context7 for authoritative external docs and API references when local context is insufficient'
applyTo: '**'
---

# Context7-aware development

Use Context7 proactively whenever the task depends on **authoritative, current, version-specific external documentation** that is not present in the workspace context.

This instruction exists so you **do not require the user to type** “use context7” to get up-to-date docs.

## When to use Context7

Use Context7 before making decisions or writing code when you need any of the following:

- **Framework/library API details** (method signatures, configuration keys, expected behaviors).
- **Version-sensitive guidance** (breaking changes, deprecations, new defaults).
- **Correctness or security-critical patterns** (auth flows, crypto usage, deserialization rules).
- **Interpreting unfamiliar error messages** that likely come from third-party tools.
- **Best-practice implementation constraints** (rate limits, quotas, required headers, supported formats).

Also use Context7 when:

- The user references **a specific framework/library version** (e.g., “Next.js 15”, “React 19”, “AWS SDK v3”).
- You’re about to recommend **non-trivial configuration** (CLI flags, config files, auth flows).
- You’re unsure whether an API exists, changed names, or got deprecated.

Skip Context7 for:

- Purely local refactors, formatting, naming, or logic that is fully derivable from the repo.
- Language fundamentals (no external APIs involved).

## What to fetch

When using Context7, prefer **primary sources** and narrow queries:

- Official docs (vendor/framework documentation)
- Reference/API pages
- Release notes / migration guides
- Security advisories (when relevant)

Gather only what you need to proceed. If multiple candidates exist, pick the most authoritative/current.

Prefer fetching:

- The exact method/type/option you will use
- The minimal surrounding context needed to avoid misuse (constraints, default behaviors, migration notes)

## How to incorporate results

- Translate findings into concrete code/config changes.
- **Cite sources** with title + URL when the decision relies on external facts.
- If docs conflict or are ambiguous, present the tradeoffs briefly and choose the safest default.

When the answer requires specific values (flags, config keys, headers), prefer:

- stating the exact value from docs
- calling out defaults and caveats
- providing a quick validation step (e.g., “run `--help`”, or a minimal smoke test)

## How to use Context7 MCP tools (auto)

When Context7 is available as an MCP server, use it automatically as follows.

### Tool workflow

1) **If the user provides a library ID**, use it directly.
  - Valid forms: `/owner/repo` or `/owner/repo/version` (for pinned versions).

2) Otherwise, **resolve the library ID** using:
  - Tool: `resolve-library-id`
  - Inputs:
	  - `libraryName`: the library/framework name (e.g., “next.js”, “supabase”, “prisma”)
	  - `query`: the user’s task (used to rank matches)

3) **Fetch relevant documentation** using:
  - Tool: `query-docs`
  - Inputs:
	  - `libraryId`: the resolved (or user-supplied) library ID
	  - `query`: the exact task/question you are answering

4) Only after docs are retrieved: **write the code/steps** based on those docs.

### Efficiency limits

- Do **not** call `resolve-library-id` more than **3 times** per user question.
- Do **not** call `query-docs` more than **3 times** per user question.
- If multiple good matches exist, pick the best one and proceed; ask a clarification question only when the choice materially affects the implementation.

### Version behavior

- If the user names a version, reflect it in the library ID when possible (e.g., `/vercel/next.js/v15.1.8`).
- If you need reproducibility (CI/builds), prefer pinning to a specific version in examples.

## Failure handling

If Context7 cannot find a reliable source:

1. Say what you tried to verify.
2. Proceed with a conservative, well-labeled assumption.
3. Suggest a quick validation step (e.g., run a command, check a file, or consult a specific official page).

## Security & privacy

- Never request or echo API keys. If configuration requires a key, instruct storing it in environment variables.
- Treat retrieved docs as **helpful but not infallible**; for security-sensitive code, prefer official vendor docs and add an explicit verification step.

© github · MIT · github/awesome-copilot

Similar IDE rules

All IDE rules for Backend and APIs →

From the same set732

The whole set →
copilot-sdk-go Instructions for developing Go applications with GitHub Copilot SDK. Guides the assistant on client initialization, streaming sessions, and event channels. ★ 40,418repo stars copilot-sdk-csharp This rule guides C# work with the GitHub Copilot SDK, from client setup to session events. Use it when adding SDK features to a project. ★ 40,418repo stars convert-jpa-to-spring-data-cosmos A step-by-step Copilot rule for moving a Spring Boot app off JPA and onto Azure Cosmos DB with Spring Data Cosmos. Useful once the migration is already decided. ★ 40,418repo stars convert-cassandra-to-spring-data-cosmos Step-by-step instructions for converting Spring Boot Cassandra projects to Azure Cosmos DB with spring-data-cosmos. Applies to Java code, build files, and application properties. ★ 40,418repo stars context-engineering A GitHub Copilot rule on file layout, types and comments, so suggestions match your project instead of drifting into generic answers. ★ 40,418repo stars containerization-docker-best-practices Guides Docker image creation with rules for multi-stage builds, process isolation, environment portability, and minimal runtime footprints. ★ 40,418repo stars coldfusion-cfm This rule sets ColdFusion conventions for *.cfm files, including query safety, application structure, and HTMX output handling. It applies while editing matching files. ★ 40,418repo stars coldfusion-cfc A Copilot rule that sets coding standards for ColdFusion components: CFScript, cfqueryparam, clean getters and setters. Useful when your repo has .cfc files. ★ 40,418repo stars

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor