/sonarqube:sonar-analyze [file-path]from sonarqube
Analyze a file for quality and security issues using SonarQube. Invoke with a file path or analyze the current file in context.
Ships in sonarqube. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Analyze code for quality and security issues using the SonarQube MCP Server.
sonar-analyze # analyze the file currently in context
sonar-analyze src/auth/login.py # analyze a specific file
This skill requires the SonarQube MCP Server to be configured and at least one of the tools mcp__sonarqube__run_advanced_code_analysis, mcp__sonarqube__analyze_file_list, or mcp__sonarqube__analyze_code_snippet to be available in your session.
Before proceeding, verify at least one of these tools is accessible. If none are, try the CLI fallback in Step 3 before giving up — don't invent other CLI commands (e.g. sonar mcp call does not exist).
If the CLI fallback also fails or doesn't apply, narrow down the cause — check whether the sonarqube MCP server is enabled in this agent's configuration.
sonar run mcp, so a correctly configured server still produces no tools if the daemon is stopped. Run docker ps yourself (falling back to podman ps / nerdctl ps) to confirm which cause applies: if it errors, the runtime is down; after the user starts it, confirm the same command succeeds before asking them to restart the agent session.Either way, show the user:
Unable to reach the SonarQube MCP Server.
Possible causes:
- MCP server not registered — invoke the sonar-integrate skill to configure the SonarQube MCP Server, then restart the agent session
- Container runtime not running — the SonarQube MCP Server runs inside a container (Docker, Podman, or Nerdctl); start your container runtime, then restart the agent session
- Credentials not configured — invoke the sonar-integrate skill
- Project key missing or invalid — pass an explicit key if needed, verify
sonar-project.properties, or re-run the sonar-integrate skill for this project
Then ask the user (yes/no) whether to run the sonar-integrate skill now. Briefly explain what it does: it checks the SonarQube setup on their machine — installing or updating sonarqube-cli and verifying authentication — and re-configures the integration for this agent, including the SonarQube MCP server and secrets-scanning hooks. If they confirm, invoke the sonar-integrate skill yourself and follow it end-to-end in this session, then ask the user to ensure a container runtime (Docker, Podman, or Nerdctl) is running and to restart the agent session so the new MCP tools become available; if they decline, stop.
Analyze one file at a time. Resolve a single file path:
Do not accept a directory as input. If the user provides one, ask them to specify a single file.
fileContent (see Step 3)."TEST" or "MAIN". Use the file path to deduce the scope. For example, if the file path contains test, spec, or __tests__, it's likely "TEST" scope.After running the sonar-integrate skill, the SonarQube MCP Server often has a default project for this workspace, so projectKey is sometimes unnecessary — pass it only when the tool schema requires it or the user targets another project.
Try mcp__sonarqube__run_advanced_code_analysis first if available. On Cloud stdio, its presence does not prove that the selected organization is entitled to Vortex; entitlement is checked on each call.
Cloud stdio selects one analysis path at startup, so an advanced-analysis session may have no local fallback. SONARQUBE_FORCE_LOCAL_ANALYSIS=true selects analyze_code_snippet directly, bypassing the IDE bridge; the analysis toolset must be enabled.
Use the vortex toolset for advanced analysis; keep analysis enabled when configuring the local snippet recovery path.
Before calling it, detect the current branch name using git branch --show-current. If git is unavailable, use main as a fallback.
Use the tool's published schema and call with:
organization — when the Cloud tool exposes it, pass the selected organization if one was chosen; otherwise use the server defaultprojectKey — omit unless the tool requires it (initial MCP configuration usually supplies the default project); if required, use the value from the user's arguments if provided, otherwise sonar.projectKey in sonar-project.properties at the repo rootbranch — detected branch namefilePath — project-relative file path (e.g. src/auth/login.py)fileContent — full file content; only pass if the tool requires it (when the MCP server has a mount, it reads the file directly and this parameter will not be required)fileScope — "TEST" or "MAIN" as a stringIf the tool is unavailable or returns an error containing Vortex is not enabled, continue with the local analysis fallbacks below. Treat that error as Vortex being unavailable for the selected organization. Report other errors, including authentication or unresolved-organization errors, and stop instead of silently falling back.
Prefer mcp__sonarqube__analyze_file_list when available (requires a running SonarQube for IDE instance bridged to this session):
file_absolute_paths — array containing the absolute path to the file (e.g. ["/home/user/project/src/auth/login.py"]); resolve it from the file path found in Step 1This tool uses the IDE's project binding and has no organization parameter.
Otherwise, use mcp__sonarqube__analyze_code_snippet when available:
organization — when exposed, preserve the organization selected for the advanced-analysis callprojectKey — pass only if exposed by the schema and needed for this projectfilePath — project-relative path when the schema requires it (mounted workspace)fileContent — complete file content when the schema requires it (unmounted workspace)language — the file's language, using a value from the schemascope — "TEST" or "MAIN" as a stringcodeSnippet only filters issues within the analyzed file; it does not replace required file content.
If no MCP analysis tool is available, fall back to the CLI's Vortex analysis:
sonar analyze agentic --file <file-path> [--file <other-file-path> ...] --format json [--branch <branch-name>] [-p <project-key>]
This uses the same Vortex backend as run_advanced_code_analysis and requires an entitled organization. After a Vortex is not enabled error, skip this CLI fallback. If neither local MCP tool is available, explain that the selected organization is not entitled to Vortex. To analyze it locally, restart the MCP server with SONARQUBE_FORCE_LOCAL_ANALYSIS=true and the analysis toolset enabled; preserve the selected organization when retrying.
If the CLI fallback fails or sonar isn't installed/authenticated, show the standard message from Prerequisites — don't guess further commands.
If issues are found, present them as a table sorted by line number:
## SonarQube Analysis — `src/auth/login.py`
Found **3 issue(s)**:
| Line | Severity | Rule | Message |
| ---- | --------- | ------------ | ----------------------------------------------------- |
| 12 | 🔴 Blocker | python:S2077 | Make sure that executing this SQL query is safe here. |
| 34 | 🟠 Major | python:S1481 | Remove the unused local variable "token". |
| 67 | 🟡 Minor | python:S1135 | Complete the task associated to this "TODO" comment. |
Severity icons (the label depends on the server version):
If no issues are found:
## SonarQube Analysis — `src/auth/login.py`
✅ No issues found.
After the results, always add:
<rule> <file>:<line> to fix a specific issue, or ask me to fix them all."What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
13 skills in this plugin
/sonar-coverageFind files with low test coverage and inspect uncovered lines in a SonarQube project (project key optional when MCP integration already defines the default project)/sonar-dependency-risksSearch for software composition analysis (SCA) dependency risks in a SonarQube project (project key optional when MCP integration already defines the default project)/sonar-duplicationFind files with code duplications in a SonarQube project and inspect duplication blocks for a file (project key optional when MCP integration already defines the default project)/sonar-fix-issueFix a specific SonarQube issue in code by rule key and location/sonar-install-cliInstalls sonarqube-cli when it is missing, or updates it to the latest version through the route it was installed with (install script, Homebrew or mise). Use when the user asks to install or update the SonarQube CLI, when `sonar` is not found, when a `sonar` command is too old for what is needed, or when another skill needs the CLI./sonar-integrateSet up SonarQube for the current agent using CLI integration locally or hosted MCP in cloud environments. Use when the user wants to connect their agent to SonarQube or configure SonarQube integration.npx claudepluginhub sonarsource/sonarqube-agent-plugins --plugin sonarqubeOther plugins' skills for the same job