Skip to main content

Overview

Rules allow you to automatically invoke Context7 for code-related questions without explicitly typing use context7 in every prompt.
Setting up a rule is the most effective way to integrate Context7 into your workflow.

Why Use Rules?

Without a rule, you need to remember to add use context7 to every prompt:
With a rule configured, Context7 is automatically invoked when needed:
The AI assistant automatically detects that this is a code-related question and invokes Context7 behind the scenes.

Setting Up Rules

The setup process varies by AI coding assistant.

Cursor Rules Setup

1

Open Cursor Settings

Go to SettingsCursor SettingsRules
2

Add a new rule

Click Add new rule or edit your existing rules file.
3

Add the Context7 rule

4

Save and test

Save the rule and try asking a code-related question without use context7.
Cursor rules can be set globally (user-level) or per-project. Project-level rules are stored in .cursorrules in your project root.
Here are different rule variations you can use depending on your needs:
When to use: General development work across various technologies.

Specific Technology Focus

When to use: When your project focuses on specific technologies.

Always-On Rule

When to use: When you want maximum automation.
Very broad rules may cause Context7 to be invoked for questions that don’t need it, potentially slowing down responses. The basic rule is usually the best balance.

Version-Specific Rule

When to use: When working with specific versions of libraries.

Advanced Rule Configuration

Project-Specific Rules

Combine Context7 rules with project-specific instructions:
.cursorrules

Combining with Library IDs

You can specify preferred library IDs in your rules:

Using ctx7 Setup Command

The easiest way to set up both the MCP server and rules is with the ctx7 setup command:
This command:
  1. Authenticates via OAuth
  2. Generates an API key
  3. Configures the MCP server
  4. Sets up the recommended rule
See the CLI documentation for more setup options.

Testing Your Rule

After setting up a rule, test it with these prompts (without adding use context7):
Expected: Context7 should be invoked automatically.
Expected: Context7 should be invoked automatically.
Expected: Context7 may or may not be invoked (this is basic JavaScript that LLMs know well).
Expected: Context7 should NOT be invoked.

Troubleshooting Rules

Solutions:
  1. Verify the rule is saved in Cursor Settings > Rules
  2. Try restarting Cursor
  3. Check if you have conflicting rules
  4. Ensure Context7 MCP is properly installed and enabled
  5. Try making the rule more explicit:
Solutions:
  1. Verify CLAUDE.md is in your project root
  2. Check the file name is exactly CLAUDE.md (all caps)
  3. Restart Claude Code
  4. Check Claude Code’s output logs for any parsing errors
Solutions:
  1. Make your rule more specific:
  2. Add exclusions:
Solutions:
  1. Make your rule more aggressive:
  2. Temporarily add use context7 to your prompts while debugging
  3. Check MCP server logs for errors

Best Practices

Start Simple

Begin with the basic recommended rule and adjust based on your experience.

Be Specific

Mention the technologies or libraries relevant to your project.

Iterate

Refine your rule over time based on what works best for your workflow.

Document

Keep your rules documented, especially in team projects.

Next Steps

Learn about specifying versions

Learn how to request specific library versions in your prompts.