Graphite Reviewer is now Diamond

How AI code review works

Sara Verdi
Sara Verdi
Graphite software engineer
Try Graphite

AI-powered code review tools are changing how developers write and maintain code. These tools can automatically review pull requests (a Git-based workflow for proposing code changes), identify potential bugs, suggest improvements, and even enforce coding standards. But how does this actually work under the hood?

When you push a commit to a branch or open a pull request, an AI code review tool kicks in. Most tools integrate with platforms like GitHub using a webhook—a small HTTP-based callback that notifies the tool when events like pull_request or push occur.

Here's what happens:

  1. Repository event triggers analysis
    A pull request is opened or updated. A webhook sends the event payload (which includes repo metadata and the diff/patch content) to the AI service.

  2. Code is cloned and parsed
    The AI tool clones your repo (or fetches only the diff) and parses the code using abstract syntax trees (ASTs). An AST is a tree representation of the code structure—think of it as the skeleton of your code, where nodes represent variables, functions, loops, etc.

  3. Static analysis and linting run first
    Before AI comes in, most tools run static analysis to find syntax errors, unused variables, or basic style violations. This is often powered by linters like ESLint (for JavaScript), flake8 (for Python), or clang-tidy (for C++).

  4. AI models analyze intent and context
    Here’s where the AI part kicks in. The tool feeds chunks of code (and diffs) into a large language model (LLM), like a fine-tuned version of GPT or Claude. These models are trained on millions of code examples and comments from public repositories, allowing them to understand patterns and flag potential problems.

    The model looks for things like:

    • Logical errors (e.g. using the wrong comparison operator)
    • Security issues (e.g. SQL injection in a query)
    • Maintainability concerns (e.g. deeply nested if-statements)
    • Bad naming or unclear function purposes

    The AI also compares the new code with the rest of the codebase to detect inconsistencies.

  5. Suggestions are generated
    The AI generates natural-language comments or inline suggestions, usually using GitHub’s Review API. It mimics a human reviewer by leaving feedback tied to specific lines of code.

    Example output in a pull request might look like this:

    Terminal
    Comment on line 22:
    Consider renaming `x` to something more descriptive, like `userId`, for better readability.
  6. Feedback is pushed back into the pull request
    You’ll see these comments in the “Files changed” tab of your pull request, just like a human reviewer left them. You can then address them, push new commits, and the process may repeat.

The AI behind these reviews uses deep learning—particularly transformer architectures. These models are trained using unsupervised learning on massive code corpora (like GitHub public repos). They learn to predict the next token in a sequence, which teaches them patterns in code structure, syntax, and logic.

Some models are further fine-tuned on specific tasks:

  • Bug detection: Labeled datasets where code snippets contain known bugs.
  • Code summarization: Paired with human-written comments.
  • Code review emulation: Paired code diffs with real pull request comments.

This fine-tuning lets the model specialize in recognizing real-world development patterns.

Diamond is Graphite's advanced AI-powered code review tool designed to provide immediate, context-aware feedback on pull requests. It builds upon previous iterations to offer enhanced capabilities that streamline the code review process. Its notable features include:

  • Codebase-aware analysis: Diamond understands the entire codebase, allowing it to provide feedback that considers the broader context of the application.

  • Customizable rules: Teams can define specific coding standards and patterns, enabling Diamond to enforce these guidelines consistently across the project.

screenshot of Diamond settings

  • Real-time feedback: Developers receive instant suggestions on pull requests, facilitating quicker iterations and reducing review cycles.

screenshot of Diamond comment

  • Suggested fixes: Diamond offers one-click code improvements, allowing developers to apply recommended changes effortlessly.

  • Integration with GitHub: Diamond works seamlessly with GitHub repositories, requiring no additional setup and functioning independently of a full Graphite subscription.

  • Privacy and security: The tool does not store or train on your code, ensuring that proprietary information remains confidential.

Incorporating Diamond into the development workflow offers several advantages:

  • Increased efficiency: By automating routine aspects of code review, Diamond reduces the time developers spend on manual reviews.

  • Improved code quality: Consistent enforcement of coding standards and immediate detection of issues lead to higher-quality codebases.

  • Scalability: Diamond's capabilities support teams of varying sizes, from individual developers to large enterprises.

Diamond is available for free for up to 100 pull requests reviewed per month, making it accessible for small teams and individual developers. For larger teams or those requiring additional features, Diamond can be purchased separately from a full Graphite subscription.

AI code reviewers like Diamond represent a significant advancement in software development, providing tools that not only enhance the efficiency of code reviews but also maintain high standards of code quality and security. By automating routine aspects of code review, these AI-assisted tools allow developers to focus on more complex and creative tasks, driving forward the evolution of software development.

Git inspired
Graphite's CLI and VS Code extension make working with Git effortless.
Learn more

Built for the world's fastest engineering teams, now available for everyone