Context Engineering: Level up your AI Code Reviews

Context is everything – especially in code reviews

At CodeRabbit, we have engineered the most context-rich code reviews in the industry. While other code review tools might skim the surface and settle for just “codebase awareness,” we go deeper. We pull in dozens of data points from your codebase to deliver reviews that are accurate and actually helpful.

We do this by packing a 1:1 ratio of code-to-context in our LLM prompts. For every line of code under review, we’re feeding the LLMs an equal weight of surrounding context. That includes key things like user intent, file dependencies, and expected outcome gathered from sources such as Jira tickets, code graph, past PRs, learnings from chat conversations, Linters, and more.

And we don’t stop there. Every suggestion from our AI is verified post-generation to reduce hallucinations, ensure accuracy, and match it to your code reviews guidelines before it ever reaches your PR.

This is context engineering – and it’s why CodeRabbit’s reviews lead the industry when it comes to relevance, quality, and trust.

In this post, we’ll look at some of the most critical data points that go into CodeRabbit’s Context Engineering approach.

CodeRabbit architecture

PR and Issue Indexing

Every code review starts with CodeRabbit cloning your repo and keeping it in a sandbox. This ensures that all reviews are completely codebase aware and the code is kept secure in an isolated environment. CodeRabbit analyzes your codebase to understand the existing file relationships, code dependencies, project structure, and patterns across your codebase. To learn more about how CodeRabbit uses GCP Cloud Run Sandboxes, check out this GCP blog.

CodeRabbit also looks at your past PRs to gather additional context including PR titles, descriptions, and affected commit ranges so that it can get more information about the "why" behind code changes. Any previous related PRs are included in the review comments. By better understanding the “why” behind code changes being reviewed, CodeRabbit generates more context-aware AI code reviews.

Additionally, we also index your issues (Jira, Linear, Github and Gitlab Issues) to understand the “intent” behind code changes. Any issue tickets attached to your PR are analyzed and an assessment of the code changes in the PR against the requirements in the linked issues is automatically generated. This helps us understand if the asks in the issue ticket is adequately addressed by the PR.

CodeRabbit assesses linked issues

Code Graph Analysis

Every time a new review is triggered, CodeRabbit builds a graph representation of code dependencies. These are re-generated each time to make sure no new dependencies are missed. Understanding how various functions depend on each other across the codebase is critical to identifying any downstream conflicts that may cause breaking changes.

CodeRabbit analyzes definitions of code symbols (e.g. Types) from this code graph and uses those definitions to enhance context when providing review comments. This helps catch more edge cases and breaking dependencies that could otherwise be missed. You can see the code definitions that were used in the review comment.

CodeRabbit code graph analysis

Custom Review Instructions

CodeRabbit includes custom review instructions specific to each team’s coding standards. Reviewing your code according to your own custom rules is a critical component of any intelligent code review and CodeRabbit provides a lot of flexibility in terms of how you can provide custom code review instructions:

  • Path-based filters: These are helpful to reduce the number of files and speed up the code review. Provide the file path in the form of a glob pattern and CodeRabbit will exclude those files from review, or provide an inverse blog pattern if you only want those files reviewed.

  • Path-based instructions: These are custom review instructions that only apply to files that match the provided glob pattern. Both path filters and instructions are highly deterministic and will kick in when the pattern matches. These are useful to include when you want certain review rules to only apply to some functions.

  • Coding agent guidelines: If you already have your coding guidelines set up in an AI coding agent (Cursor, Copilot, Cline, Windsurf, etc.) then CodeRabbit can import them and use those existing rules in its code reviews. Just provide the rules file path and we will import the code guidelines.

Learnings from chat: This is a simple and intuitive way to provide feedback on review comments. Don’t like something in the review? Just chat with CodeRabbit and tell it you don’t want those kinds of comments or you would like it to analyze similar issues through a specific lens and it will include your chat feedback in future code reviews.

CodeRabbit learnings from chat

Linters and Static Analyzers

CodeRabbit packages 40+ Linters/SAST tools with zero-touch configuration needed from the user. While most customers may have some Linters pre-configured, we provide a much more comprehensive set of Linters. These Tools are automatically invoked during the code review process and their results are validated by our verification agent to cut down on the noise that’s often typical of Linters. A more exhaustive list of Linters helps catch more bugs.

We check your code by running it through all of the 40+ supported Linters that are relevant to the code in question.. If you prefer to use your config file and the tool supports a custom config file, then you can provide the file path for your config file and we will use the rules from your config file in code reviews. When a bug is caught because of a Linter, you will see that called out in the review comment.

You can check out the full list of supported Linters in our documentation.

CodeRabbit Linters

Web Query

Sometimes the underlying LLM used in reviews may not be up to date to review the code accurately. For example: the LLM may not be aware of a latest security update or a new patch release for a particular programming language. In those cases, CodeRabbit will run a real-time web query to fetch technical information from publicly available release notes or technical documentation and include that in the code review.

This helps ensure your code review includes the latest info and doesn’t accidentally flag errors due to outdated info. In the example below, the code was referencing Go version 1.23.6, and the LLM was not aware of a newer version, but CodeRabbit was able to run a Web Query and figure out that actually the latest Go version is 1.24.1 and recommended the user to refer to the latest Go release.

CodeRabbit web query

Verification Scripts

Lastly, CodeRabbit also runs verification scripts on the review comments provided by the LLMs to make sure that the review comments will meaningfully improve the codebase. These verification scripts are generated in the sandbox and any low value feedback is automatically filtered out and not passed on to the user, helping filter out most of the AI hallucinations that can sometimes occur.

CodeRabbit verification script

Industry leading context engineering for better code reviews

As you can see, CodeRabbit has an extensive Context Engineering approach that ultimately provides more accurate code reviews by giving LLMs just the right amount of contextual information to catch more bugs without overwhelming them.

We achieve this by:

  • Understanding the intent behind code changes to catch otherwise hard to find bugs

  • Feeding the right amount of information to LLMs with a 1:1 ratio of code to context

  • Filtering out low value review comments to maintain a high signal to noise ratio

If you’d like to give CodeRabbit a try, we offer a free 14-day trial and it only takes a couple of minutes to give access to your repo. Let us know if you have any questions on Discord!

0
Subscribe to my newsletter

Read articles from Sahil Mohan Bansal directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Sahil Mohan Bansal
Sahil Mohan Bansal