Skip to main content
In this guide, we’ll explore how to harness Cursor AI’s contextual references to focus on exactly the code you need—whether it’s specific files, functions, or even GitHub pull requests. By including or excluding contexts, you’ll get sharper, more relevant answers for code exploration and review.

1. Adding Context from Your Codebase

You can click Add Context on any file (or even just select particular functions) to include them in your AI session. For example, here’s our app.py:
Never commit sensitive values like SECRET_KEY or database credentials in your production code. Use environment variables or a secrets manager instead.

2. Querying Specific Contexts: Templates & Templating Engines

You can narrow your search to HTML templates and ask, “Which templating system do these use?” The AI will identify Jinja2, Flask’s default engine:
The image shows a code editor with a Python file open on the left and a chat interface on the right, discussing the Jinja2 template system used in Flask applications.

3. Excluding Irrelevant Files

Context exclusion is just as powerful. You can omit JavaScript files, tests, or any directories that aren’t relevant:

4. Focusing on Individual Functions

To optimize a specific routine, just select the function. For example, a simple password hashing utility:
Or isolate the get_db() function to ask for performance improvements. The AI might suggest enabling WAL mode, tuning cache sizes, and using autocommit:
Performance tuning PRAGMAs can greatly reduce disk I/O and improve concurrency for SQLite-based applications.

5. Integrating with GitHub Contexts

Cursor can also pull in GitHub data—search commits, PRs, or specific files in a repo. For instance, to review database-layer changes in your pull requests:
By mixing and matching contexts—local files, folders, or GitHub references—you guide the AI to focus on exactly what matters. This precision leads to more accurate insights and a streamlined code review process.

Watch Video