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.
On this page:
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.phpfile (Not recommended).
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-6claude-sonnet-4-6
-
Google Gemini:
gemini-1.0-progemini-2.5-flashgemini-3.1-flash-lite-preview
-
OpenAI:
-
gpt-4
-
-
LM Studio:
lmstudio-community/gemma-3-1B-it-qat-GGUFlmstudio-community/Qwen3-1.7B-GGUFlmstudio-community/DeepSeek-R1-Distill-Llama-8B-GGUFlmstudio-community/Meta-Llama-3.1-8B-Instruct-GGU
In this section: