Overview
Rules allow you to automatically invoke Context7 for code-related questions without explicitly typinguse context7 in every prompt.
Why Use Rules?
Without a rule, you need to remember to adduse context7 to every prompt:
Setting Up Rules
The setup process varies by AI coding assistant.- Cursor
- Claude Code
- Other Clients
Cursor Rules Setup
Cursor rules can be set globally (user-level) or per-project. Project-level rules are stored in
.cursorrules in your project root.Recommended Rule Examples
Here are different rule variations you can use depending on your needs:Basic Rule (Recommended)
Specific Technology Focus
Always-On Rule
Version-Specific Rule
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 thectx7 setup command:
- Authenticates via OAuth
- Generates an API key
- Configures the MCP server
- 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 addinguse context7):
Test 1: Framework-specific question
Test 1: Framework-specific question
Test 2: Library setup question
Test 2: Library setup question
Test 3: General coding question
Test 3: General coding question
Test 4: Non-code question
Test 4: Non-code question
Troubleshooting Rules
Rule not working in Cursor
Rule not working in Cursor
Solutions:
- Verify the rule is saved in
Cursor Settings > Rules - Try restarting Cursor
- Check if you have conflicting rules
- Ensure Context7 MCP is properly installed and enabled
- Try making the rule more explicit:
Rule not working in Claude Code
Rule not working in Claude Code
Solutions:
- Verify
CLAUDE.mdis in your project root - Check the file name is exactly
CLAUDE.md(all caps) - Restart Claude Code
- Check Claude Code’s output logs for any parsing errors
Context7 invoked too often
Context7 invoked too often
Solutions:
- Make your rule more specific:
- Add exclusions:
Context7 not invoked when needed
Context7 not invoked when needed
Solutions:
- Make your rule more aggressive:
- Temporarily add
use context7to your prompts while debugging - 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.