From sonarqube-skill
Use this skill for any SonarQube or code quality workflow: fixing a PR quality gate, triaging and fixing codebase issues, reviewing security hotspots, improving coverage, or getting an overview of project health. Trigger on: "sonarqube", "quality gate", "sonar issues", "code smells", "hotspots", "coverage gap", "fix sonar", "fix PR gate", "sonar failing", or any implicit request to improve code quality metrics.
How this skill is triggered — by the user, by Claude, or both
Slash command
/sonarqube-skill:sonarqubeThis skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
Both are required for all API calls. Resolve in this order:
Both are required for all API calls. Resolve in this order:
sonar-project.properties → sonar.projectKey + sonar.organization.sonarlint/connectedMode.json → projectKeypackage.json → sonar.projectKey.github/workflows/*.yml) for sonar configsearch_my_sonarqube_projects to list/searchAskUserQuestionStore as PROJECT_KEY and SONARQUBE_ORGANIZATION. Scripts also read these from env.
--pr → PR gate fix workflow--fix → general issue fix workflow--hotspots → security hotspot review--coverage → coverage improvement--triage → triage-only (no fixes, just plan)AskUserQuestion: "What do you want to do?
1. Fix failing PR quality gate (--pr)
2. Fix codebase issues by severity (--fix)
3. Review security hotspots (--hotspots)
4. Improve test coverage (--coverage)
5. Triage only — show me a plan without fixing"
Fire all relevant MCP calls in parallel in a single message (no subagents — orchestrator only).
--pr)git rev-parse --abbrev-ref HEAD to get current branch namelist_pull_requests(project: PROJECT_KEY) to find matching PR
branch field in results<name>. Push the branch and wait for CI to complete, then re-run."PR_IDget_project_quality_gate_status(project: PROJECT_KEY, pullRequest: PR_ID)search_sonar_issues_in_projects(projects: PROJECT_KEY, pullRequest: PR_ID, severities: "BLOCKER,CRITICAL,MAJOR")search_security_hotspots(project: PROJECT_KEY, pullRequest: PR_ID)--fix)In parallel:
get_project_quality_gate_status(project: PROJECT_KEY)get_component_measures(component: PROJECT_KEY, metricKeys: "bugs,vulnerabilities,code_smells,duplicated_lines_density,coverage,reliability_rating,security_rating,sqale_rating")search_sonar_issues_in_projects(projects: PROJECT_KEY, severities: "BLOCKER,CRITICAL")search_security_hotspots(project: PROJECT_KEY, status: "TO_REVIEW")--coverage)In parallel:
get_project_quality_gate_status(project: PROJECT_KEY)get_component_measures(component: PROJECT_KEY, metricKeys: "coverage,uncovered_lines,lines_to_cover,uncovered_conditions")search_files_by_coverage(project: PROJECT_KEY, maxCoverage: 50)--hotspots)search_security_hotspots(project: PROJECT_KEY, status: "TO_REVIEW")Skip for --hotspots and --coverage modes — go directly to Phase 3B or 3D.
Extract unique rule keys from all issues returned in Phase 1.
Fetch rule descriptions — run this script (no MCP needed, direct REST):
python3 ~/.claude/plugins/sonarqube-skill/skills/sonarqube/scripts/fetch_rules.py <key1> <key2> ...
Pass SONARQUBE_TOKEN, SONARQUBE_ORGANIZATION, SONARQUBE_URL as env vars (URL defaults to https://sonarcloud.io).
python3 ~/.claude/plugins/sonarqube-skill/skills/sonarqube/scripts/triage_issues.py \
--issues /tmp/sq_issues.json \
--rules /tmp/sq_rules.json
Found N issues across M files:
- X quick wins (1-line fixes)
- Y complex fixes
- Z hotspots to review
- W accept/FP candidates
Files to fix: [list top 5]
AskUserQuestion: "Approve this fix plan? (yes / adjust / cancel)"
For each file in the by_file map from triage JSON:
python3 ~/.claude/plugins/sonarqube-skill/skills/sonarqube/scripts/build_fix_prompt.py \
--template ~/.claude/plugins/sonarqube-skill/skills/sonarqube/agents/fix-agent.md \
--file "src/path/to/file.ts" \
--issues '[{"rule":"...","message":"...","line":42,"ruleDescription":"...","compliantExample":"..."}]'
Spawn one general-purpose Agent per file with the result as the prompt, run_in_background: true.
After all agents complete, verify each file in parallel:
mcp__sonarqube__analyze_code_snippet(code: <file contents>, language: "ts")
Fix agents may report items they skipped as "needs user review" with a risk explanation.
Collect all such reports and present them via AskUserQuestion before deciding whether to proceed.
For each hotspot:
show_security_hotspot(key: hotspot.key) → show to userAskUserQuestion: "How to handle <message> in <file>:<line>?
change_security_hotspot_status(hotspot: key, status: "SAFE")change_security_hotspot_status(hotspot: key, status: "ACKNOWLEDGED")For accept/FP candidates approved in triage:
change_sonar_issue_status(issue: key, transition: "accept") or "falsepositive"Two chained agents per file: a planner that understands the code and designs real behavioral contracts, then an executor that writes the tests from the plan. This prevents vacuous coverage.
Identify target files (lowest coverage, from search_files_by_coverage)
Calculate: lines needed to reach the gate threshold
For each target file — run in parallel across files, sequential within each file:
Step 1 — Planner (foreground, must complete before executor):
Call get_file_coverage_details(project: PROJECT_KEY, file: FILE_PATH) to retrieve the list
of uncovered line numbers for this file. Store the result as UNCOVERED_LINES (a JSON array
of integers, e.g. [42, 43, 67, 88]). Then build the planner prompt:
# FILE_PATH and UNCOVERED_LINES are populated from MCP call results above
PLANNER_PROMPT=$(sed \
-e "s|{{FILE_PATH}}|$FILE_PATH|g" \
-e "s|{{UNCOVERED_LINES}}|$UNCOVERED_LINES|g" \
-e "s|{{TEST_FILE_PATH}}|src/path/to/file.test.ts|g" \
~/.claude/plugins/sonarqube-skill/skills/sonarqube/agents/coverage-planner-agent.md)
Spawn general-purpose Agent with planner prompt. Wait for result (foreground).
The planner outputs a JSON test plan to its report.
Step 2 — Executor (after planner completes):
Inject planner's JSON output as {{TEST_PLAN}} into coverage-executor-agent.md.
Spawn general-purpose Agent with executor prompt, run_in_background: true.
After all executors complete: show report of cases written vs skipped per file.
/tmp/sq_after.json)python3 ~/.claude/plugins/sonarqube-skill/skills/sonarqube/scripts/gate_delta.py \
/tmp/sq_before.json /tmp/sq_after.json
Output is a markdown table — present it to user.
pullRequest: PR_ID to scope to new code only.SONARQUBE_URL defaults to https://sonarcloud.io if not set.Guides creation, editing, and verification of skills for AI coding agents using test-driven development with subagent scenarios. Use when authoring or debugging skills.
npx claudepluginhub ahlombardini/skills --plugin sonarqube-skill