For the complete documentation index, see llms.txt. This page is also available as Markdown.
Developer

Overview

Plug the SonarQube CLI into your editor, AI coding assistants, and Git workflow so analysis runs automatically.

The SonarQube CLI ships first-class integrations for the tools you use every day. Run sonar integrate with no subcommand to pick a tool from an interactive list, or call a subcommand directly (for example, sonar integrate claude). Each integration connects SonarQube to one of these tools. It installs secrets-detection hooks, configures the MCP server where applicable, and sets up Sonar Vortex agentic analysis features on SonarQube Cloud.

What's available

Claude CodeCursorGitHub Copilot CLIGoogle AntigravityOpenAI CodexGit hooks

Project versus global scope

Every sonar integrate command (bare or subcommand) installs at project scope (inside the current repository) or global scope (in your user home, applying across projects on your machine):

Scope
Flag
Where files are installed
When to use

Project

none (default)

Inside your repository (.claude/, .copilot/, .cursor/, Codex config, .git/hooks/)

Per-repo configuration. The hook ships with the repo and applies only when working in that project.

Global

--global

In your user home (~/.claude/, ~/.copilot/, ~/.cursor/, ~/.codex/, ~/.sonar/sonarqube-cli/hooks/)

Apply once, get the integration across every project on your machine. Recommended for individual developers and for security baselines.

The --project / -p flag sets the SonarQube project key. Passing it implies project scope and skips the scope prompt. When you omit it, the CLI resolves the project from sonar-project.properties, SonarQube for IDE connected mode, or the git origin remote when the repository is bound on SonarQube.

In an interactive terminal, when you omit both --global and --project, the CLI shows the connection and project preflight summary, then asks where to install. Choose This project for the current directory, or Global for your user home.

In non-interactive mode (including when you authenticate with environment variables), scope defaults to project when you don't pass --global. The CLI logs an info line recording that default.

If you install a global integration first and then run the same sonar integrate command in a project, the CLI detects the existing global setup and skips redundant hook installation.

What gets installed

AI agent integrations (sonar integrate claude, copilot, codex, cursor, and antigravity) install three categories of features, though the exact mechanism varies by agent:

  • Secrets-scanning hook(s). For Claude Code, a UserPromptSubmit hook (scans the prompt you send to Claude) and a PreToolUse hook (runs before file reads/writes). For GitHub Copilot, a pre-tool-use hook. For OpenAI Codex, a UserPromptSubmit hook (scans the prompt before it is sent to Codex), plus instructions to scan files for secrets before reading them. For Cursor, a beforeSubmitPrompt hook plus beforeReadFile and preToolUse hooks that scan files before the agent reads them. These all block any operation that would expose a secret. Powered by sonar analyze secrets.

  • MCP server configuration. Lets the agent call SonarQube directly to fetch projects, issues, and rules.

  • Agentic analysis integration (SonarQube Cloud only). For Claude Code, a PostToolUse hook runs fast STANDARD analysis after each edit, plus end-of-turn DEEP instructions in CLAUDE.md. For OpenAI Codex, a PostToolUse hook runs DEEP change-set analysis after each apply_patch. For GitHub Copilot, Cursor, and Google Antigravity, instructions tell the agent to run one end-of-turn DEEP sonar analyze agentic command (multi --file or git change set). Agentic analysis is project-scoped: --global installs skip it.

  • Sonar Vortex context augmentation skill (SonarQube Cloud only, when your organization is entitled on an eligible SonarQube Cloud plan). On eligible project installs, the integrate commands install a skill that lets the agent pull project guidelines, architecture, semantic navigation, and dependency context through the CLI integration as it works. Context augmentation is project-scoped: --global installs skip it, and --skip-context opts out.

sonar integrate git installs code scanning hooks at the Git layer, so commits and pushes are blocked even outside of an AI agent's session. Every hook runs secrets scanning; you can optionally enable dependency-risks scanning on the pre-commit hook. See Git hooks.

Install confirmation

After you select which features to install (or when non-interactive mode accepts every eligible feature), the CLI shows a What will be installed summary. It lists each accepted feature with a short description of what it does.

In interactive mode, press Enter when prompted to proceed with installation. In non-interactive mode (--non-interactive or environment-variable auth), the summary is printed and installation proceeds without a confirmation prompt.

Removing installed features

When you re-run a sonar integrate command interactively, the CLI asks whether to keep each feature that's already installed for that integration. Decline to keep a feature and the CLI warns you, then asks you to confirm removal. Confirming tears down the feature's files and configuration, prunes the recorded state, and uninstalls auxiliary binaries that no longer have any referrer.

  • Installed features prompt <name> (currently installed) Keep? (default Yes)

  • Declining shows a warning, then Proceed with removal? (default Yes)

  • The completion summary lists removed features under Removed

  • Config files that held only Sonar-managed content (for example, .mcp.json or hook JSON) are deleted instead of left empty; files with your own or other integrations' content are kept with Sonar entries pruned

  • Features that aren't installed yet follow the existing opt-in install flow

  • Container features (for example, the git pre-commit hook group) are removed as a whole; the CLI doesn't prompt per subfeature

  • In non-interactive mode (--non-interactive or environment-variable auth), the CLI never offers to remove features; it keeps existing installs and only adds what's missing

To remove everything at once, use Reset the CLI or the manual steps in Uninstalling.

When Sonar Vortex agentic analysis is no longer available

If your organization's Sonar Vortex agentic analysis entitlement is revoked, any installed agentic analysis hooks (for example, the Claude Code or Codex PostToolUse hooks) start receiving HTTP 403s from the analysis API. The hook prints a notice directing you to run sonar integrate to remove the unavailable hooks, with a link to Sonar Agent Essentials. Re-run the integrate command interactively and decline to keep the agentic analysis feature to remove the hooks and related configuration.

This gives every project on the machine secrets blocking at three layers: AI agent reads, AI agent writes, and Git commits/pushes.

For larger rollouts (dozens to thousands of engineers), pair the per-machine global integrations above with a CI-side scan that catches anything the local hooks missed:

See Environment variables and Exit codes for the CI/CD recipe.

Last updated

Was this helpful?