AI for code analysis

P4 Code Review enhances the code review process by using AI-powered code analysis to generate explanations for code diffs. This can help reviewers understand unfamiliar code, identify important changes, and review complex diffs more efficiently.

AI code analysis can use administrator-managed AI vendors or AI vendors configured by individual users.

To learn more about configuring personal AI vendors, see Manage AI Vendors.

Overview

You can use AI code analysis to analyze a specific diff block or a selected portion of code. Click the AI button next to a diff block to generate an explanation of the changes in that block, or select code to analyze only the selected content.

When AI analysis is performed, P4 Code Review sends only the information required to generate the analysis:

  • The selected code or the selected diff block.

  • The file name.

  • The file extension.

P4 Code Review does not send the entire file.

The generated AI analysis is displayed in a pop-up window.

Per-user AI vendors (bring your own key)

In addition to administrator-managed AI vendors, users can configure their own AI vendors and API keys.

A user's personal AI vendor is used for that user's AI actions. If a user does not have a personal vendor configured for a vendor type, P4 Code Review uses the administrator-managed vendor instead.

For administrators

Personal AI vendor keys are enabled by default for all supported AI vendors.

To manage personal AI vendors:

  1. Go to System Information > Configuration > AI Configuration.

  2. Select Allow personal AI vendor keys to enable or disable personal AI vendors.

  3. Select Vendors allowed for personal keys to specify which vendors users can configure with their own API keys.

  4. Click Save configuration.

You can enable personal AI vendor keys while restricting vendors that support custom or local-network endpoints, such as:

AI Checklist always uses the administrator-managed AI vendor and never uses a user's personal AI vendor.

To learn more about Checklists, see Checklists.

Users' API keys are not visible to administrators. When encryption at rest is enabled, personal API keys are stored encrypted.

For users

To create a personal AI vendor:

  1. In the top right corner of P4 Code Review, click your user ID, then click My Profile.

  2. Click the AI Vendors tab.

  3. Click Add Vendor.

  4. Select the AI vendor you want to configure and configure the vendor settings.

  5. Click Add AI Vendor.

  6. Click Test connection to verify that P4 Code Review can connect to the AI vendor.

    Test connection requires an API key. If the API key field is blank, the test fails.

    For AI vendors that do not require authentication, enter a placeholder value.

To learn more, see My Profile.

Users can configure up to 10 personal AI vendors.

When performing an AI action, users can choose either a personal AI vendor or an administrator-managed AI vendor.

If a user leaves a setting blank, such as the model, endpoint, API version, character limits, or maximum output tokens, the administrator-managed value is used instead.

Migrating from config.php-based AI configuration

AI configuration is managed through the P4 Code Review user interface.

Administrators configure organizational AI settings in System Information > Configuration.

When enabled by an administrator, users can configure Personal AI vendors in My Profile > AI Vendors.

If your SWARM_ROOT/data/config.php file contains an ai_review block from an earlier release, its values are copied into the Configuration tab the first time you open it.

After that, changes to the ai_review block in config.php have no effect.

Remove the ai_review block from config.php once your AI configuration is saved in System Information or My Profile.

Use AI code analysis

Analyze a diff block

  1. Open a review.

  2. Open a file diff.

  3. Click the AI button in the file diff panel.

  4. Select the AI vendor you want to use for the AI code analysis.

P4 Code Review generates an explanation of the changes in the selected diff block.

A loading indicator appears while the analysis is generated.

AI code analysis analyzes a specific diff block or code selection. To automatically analyze all file diffs in a review, configure AI-enabled checklist items. For more information, see Checklists.

Analyze selected code

  1. Open a review.

  2. Open a file diff.

  3. Select the portion of code you want to analyze.

  4. Click the AI button .

P4 Code Review generates an explanation for the selected code.

AI vendor selection

Available AI analysis options depend on the AI vendors available to your account. This can include administrator-managed AI vendors, personal AI vendors, or both.

Depending on your configuration, you may be able to choose from multiple AI vendors, models, and prompts when requesting AI analysis.

To learn more about configuring personal AI vendors, see Manage AI Vendors.

Supported AI vendors and models

P4 Code Review supports integration with multiple AI vendors and models.

The following AI vendors have been tested with P4 Code Review:

  • Anthropic Claude:

    • claude-opus-4-6
    • claude-sonnet-4-6
  • Azure OpenAI:

    • gpt-4o deployments

  • Google Gemini:

    • 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-GGUF
AI Checklist requires a model that returns valid JSON. For OpenAI, use gpt-4o-mini or newer. The base gpt-4 model is not supported for AI Checklist.

For more information on how to configure each of these AI vendors, see the following pages: