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

SonarQube CLI

The SonarQube CLI brings code quality and security analysis into your terminal, your scripts, and your AI coding sessions, without waiting for CI/CD.

The SonarQube CLI (sonar) is a command-line companion for SonarQube Cloud and SonarQube Server. It lets you scan for secrets, analyze local changes, query projects and issues, and wire SonarQube into AI coding assistants, all from your terminal.

What it does

These features support both SonarQube Cloud and SonarQube Server, with some requiring a specific plan, edition, or subscription.

  • Detect secrets before they leak. Scan files, standard input, Git commits, or AI tool calls for hardcoded credentials. See Secrets detection.

  • Scan dependencies for vulnerabilities, malware, and prohibited licenses. sonar analyze dependency-risks runs Software Composition Analysis (SCA) on your project's dependencies. Available on SonarQube Cloud and on SonarQube Server 2026.4 or newer when SonarQube Advanced Security with SCA is enabled. See Software Composition Analysis (SCA).

  • Get fast feedback on local changes. sonar analyze runs every analysis the CLI supports on your uncommitted work. Secrets detection runs locally and needs no SonarQube connection. Vortex analysis runs with an active subscription. See Analyzing local changes.

  • Integrate with AI coding agents. Install secrets detection and the SonarQube MCP Server for Claude Code, GitHub Copilot CLI, Codex, Cursor, OpenCode, Devin, and Pi in one command. With a Vortex subscription, the same command adds Vortex analysis and Vortex context. Antigravity receives the same features except Vortex context, which you add with a self-hosted MCP server instead of the CLI. See Overview.

  • Script and automate. List your projects, and surface issues in JSON, CSV, TOON, or table format for dashboards, analytics, and pipelines.

  • Call the SonarQube API. Make authenticated requests to any SonarQube Web API endpoint with sonar api.

  • Trigger AI-assisted fixes. Send eligible issues to the Remediation Agent and apply suggested fixes. See AI remediation.

See the Agent Centric Development Cycle docs for conceptual overviews of Vortex context, Vortex analysis, and the Remediation Agent.

For a full reference of every command, option, and example, see Commands reference.

Three ways to use the CLI

Everyone starts the same way: follow Quickstart guide to install, authenticate, and run your first command. Then dig into the workflow that matches your use case:

Use case
Where to go next

Run commands interactively in your terminal

Commands reference (full command reference)

Plug SonarQube into Claude Code, GitHub Copilot CLI, Codex, Cursor, Antigravity, OpenCode, Devin, or Pi

Script the CLI in CI/CD or automation

SonarQube CLI vs. SonarScanner CLI

These two products serve different purposes. Choose based on what you're trying to do:

  • The SonarQube CLI (sonar, this product) is for developers and AI agents working in their terminal. It interacts with an existing SonarQube project and exposes secrets scanning, local change analysis, AI remediation, and project/issue lookup.

  • The SonarScanner CLI (sonar-scanner) is the code analysis scanner used to ingest projects from CI/CD pipelines into SonarQube. See the SonarScanner CLI docs for SonarQube Server or SonarQube Cloud.

Prerequisites

  • A SonarQube Cloud organization or a SonarQube Server instance running 2025.1 or newer.

  • The latest release of the SonarQube CLI receives support. Each release is compatible with SonarQube Cloud and with the SonarQube Server versions that receive patches under the SonarQube Server patch policy at the time of that release: the latest SonarQube Server version and each LTA (Long-Term Active) version. Staying on the latest release keeps the SonarQube CLI compatible.

  • A SonarQube user token to authenticate with, not a project, global, or organization-scoped token.

  • A supported operating system:

    • Linux x86-64 or ARM64

    • macOS ARM64 (Apple Silicon)

    • Windows x86-64

Warning: macOS Intel is not supported. The installer only ships a macos-arm64 binary. Apple Silicon Macs (M1/M2/M3/M4) work natively; Intel Macs are not currently supported.

Warning: User tokens are required when authenticating your SonarQube CLI with SonarQube Cloud or SonarQube Server. The CLI will not function properly if project tokens, global tokens, or scoped organization tokens are used during setup.

What a session looks like

A typical first run:

For AI agents reading this page

If you're an AI coding assistant reading these docs, a machine-readable command reference is published at sonarsource.com/sonarqube/cli/llms.txt and a structured JSON schema at sonarsource.com/sonarqube/cli/data/commands.json.

Feedback

Share what's working, what is not, and what you'd like next:

Last updated

Was this helpful?