AI for code analysis

P4 Code Review enhances the code review process by using an AI model (similar to those from OpenAI) to generate explanations for code diffs in a file, making it easier for developers to understand and review changes.

Overview

You can send either the full diff of a file or a selected portion of code for AI code analysis.

To analyze the full diff, click the AI button in the file diff panel.

To analyze selected code:

  • Select the code in the diff.

  • Click the AI button .

A loading indicator appears while the analysis is generated.

The AI code analysis is returned as text in a pop window.

Only the following data is sent to the AI model:

  • The file diff (or selected portion).

  • The filename.

  • The file extension.

P4 Code Review does not send the full file.

An AI Assistant is also available for comments on a review page. For details, see AI Assistant for comments.

Set up AI

Configure P4 Code Review to use your AI provider in the System Information page. To learn more, see Configuration.

There are two ways to configure AI in P4 Code Review:

  • Use AI configuration in System Information (Recommended).

  • Use the ai_review block in the SWARM_ROOT/data/config.php file (Not recommended).

If you have upgraded to P4 Code Review 2026.1 and are using the AI configuration UI, add your configuration through the UI as described in the System Information section. Changes made directly in config.php do not take effect.

To review the terms for using your own API keys, download the API Key Usage Agreement for Perforce P4 Code Review.

AI vendors and models

P4 Code Review has been tested with the following AI vendors and models:

  • Anthropic Claude:

    • claude-opus-4-6
    • claude-sonnet-4-6
  • Google Gemini:

    • gemini-1.0-pro
    • gemini-2.5-flash
    • gemini-3.1-flash-lite-preview
  • OpenAI:

    • gpt-4

  • LM Studio:

    • lmstudio-community/gemma-3-1B-it-qat-GGUF
    • lmstudio-community/Qwen3-1.7B-GGUF
    • lmstudio-community/DeepSeek-R1-Distill-Llama-8B-GGUF
    • lmstudio-community/Meta-Llama-3.1-8B-Instruct-GGU

In this section: