/code-quality:sonarqube [PR number or URL]from code-quality
Analyzes SonarCloud quality issues for a specific pull request and produces a report with metrics, top violators, and an action plan. Read-only; no code changes.
Ships in code-quality. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description, though model invocation is off: only you can start it.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Analyze SonarCloud quality issues for a specific PR. Generates comprehensive report with metrics, top violators, and action plan.
Core principle: Analysis-only = no code changes, pure insight.
$SONARQUBE_TOKEN environment variable# Set SonarQube token (add to ~/.bashrc or ~/.zshrc)
export SONARQUBE_TOKEN="your_token_here"
# Verify token is set (never print its value)
[ -n "$SONARQUBE_TOKEN" ] && echo "token set" || echo "token missing"
To get token:
Configure your SonarCloud project details:
# Add to project's CLAUDE.md or as environment variables
export SONAR_ORGANIZATION="your-org-name"
export SONAR_PROJECT_KEY="your-org_your-project"
export SONAR_BASE_URL="https://sonarcloud.io/api"
If not set: Ask user to provide organization and project key.
Important: Direct curl with -u "$SONARQUBE_TOKEN:" fails in zsh due to authentication parsing. Use bash script wrapper:
# Create temporary bash script to handle authentication
T="${TMPDIR:-/tmp}"
cat > "$T/fetch_sonar.sh" << 'SCRIPT'
#!/bin/bash
: "${SONARQUBE_TOKEN:?is not set or not exported}"
: "${SONAR_PROJECT_KEY:?is not set or not exported}"
curl -sS -f -u "${SONARQUBE_TOKEN}:" \
"https://sonarcloud.io/api/issues/search?componentKeys=${SONAR_PROJECT_KEY}&pullRequest=\$1&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true&ps=500"
SCRIPT
chmod +x "$T/fetch_sonar.sh"
"$T/fetch_sonar.sh" "$PR_NUMBER" > "$T/sonar_pr_$PR_NUMBER.json" \
|| { echo "NOT RUN: SonarCloud request failed"; exit 1; }
If the request fails, stop: report the analysis as NOT RUN with the error, and produce no issue counts.
API Parameters:
componentKeys: Your project keypullRequest: PR numberissueStatuses: OPEN,CONFIRMED (exclude resolved)sinceLeakPeriod: Only new issues in this PRps: Page size (max 500)Create a Node.js analysis script at $TMPDIR/sonar_analyze.js (fall back to /tmp):
const fs = require('fs');
const prNumber = process.argv[2];
const tmp = process.env.TMPDIR || '/tmp';
const data = JSON.parse(fs.readFileSync(`${tmp}/sonar_pr_${prNumber}.json`, 'utf8'));
if (!Array.isArray(data.issues)) {
console.error(`NOT RUN: no issues array in the response: ${JSON.stringify(data.errors || data)}`);
process.exit(1);
}
const issues = data.issues;
// Group by severity
const bySeverity = issues.reduce((acc, i) => {
acc[i.severity] = (acc[i.severity] || 0) + 1;
return acc;
}, {});
// Group by type
const byType = issues.reduce((acc, i) => {
acc[i.type] = (acc[i.type] || 0) + 1;
return acc;
}, {});
// Group by file
const byFile = issues.reduce((acc, i) => {
const file = i.component.split(':')[1] || i.component;
acc[file] = (acc[file] || 0) + 1;
return acc;
}, {});
// Group by rule
const byRule = issues.reduce((acc, i) => {
if (!acc[i.rule]) {
acc[i.rule] = {
count: 0,
severity: i.severity,
message: i.message
};
}
acc[i.rule].count++;
return acc;
}, {});
// Output structured data
console.log(JSON.stringify({
total: data.total,
bySeverity,
byType,
topFiles: Object.entries(byFile)
.sort((a, b) => b[1] - a[1])
.slice(0, 10),
topRules: Object.entries(byRule)
.map(([rule, d]) => ({ rule, ...d }))
.sort((a, b) => b.count - a.count)
.slice(0, 5)
}, null, 2));
Run analysis:
node "$T/sonar_analyze.js" "$PR_NUMBER" > "$T/sonar_analysis_$PR_NUMBER.json"
Generate formatted report from analysis:
📊 SonarCloud Analysis - PR #XXX
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
📈 EXECUTIVE SUMMARY
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Total Issues: {TOTAL}
By Severity:
🔴 Blocker/Critical: {COUNT} ({PERCENTAGE}%)
🟡 Major: {COUNT} ({PERCENTAGE}%)
🔵 Minor/Info: {COUNT} ({PERCENTAGE}%)
By Type:
🐛 Bugs: {COUNT}
🛡️ Vulnerabilities: {COUNT}
🧹 Code Smells: {COUNT}
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
📂 TOP 10 FILES WITH ISSUES
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1. src/components/UserProfile.tsx - 8 issues
2. src/services/auth.service.ts - 5 issues
3. src/utils/validation.ts - 4 issues
...
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠️ TOP 5 VIOLATED RULES
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1. typescript:S1854 (MAJOR) - 12 occurrences
"Dead stores should be removed"
2. typescript:S3776 (CRITICAL) - 8 occurrences
"Cognitive Complexity of functions should not be too high"
3. typescript:S1186 (MINOR) - 6 occurrences
"Functions should not be empty"
...
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✅ ACTION PLAN
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Priority 1 - CRITICAL/BLOCKER ({COUNT} issues):
• Fix immediately before merge
• Focus on: {TOP_FILES}
Priority 2 - MAJOR ({COUNT} issues):
• Address in this PR if possible
• Consider technical debt ticket if extensive
Priority 3 - MINOR/INFO ({COUNT} issues):
• Can be addressed in follow-up PR
• Add to backlog for refactoring sprint
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🔗 LINKS
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
View in SonarCloud:
https://sonarcloud.io/project/pull_requests_list?id={PROJECT_KEY}&pullRequest={PR_NUMBER}
| SonarCloud | Symbol | Priority | Action |
|---|---|---|---|
| BLOCKER | 🔴 | P0 | Fix immediately |
| CRITICAL | 🔴 | P0 | Fix immediately |
| MAJOR | 🟡 | P1 | Fix in this PR |
| MINOR | 🔵 | P2 | Consider for follow-up |
| INFO | 🔵 | P3 | Optional improvement |
| Type | Symbol | Description |
|---|---|---|
| BUG | 🐛 | Code that is demonstrably wrong |
| VULNERABILITY | 🛡️ | Security issues |
| CODE_SMELL | 🧹 | Maintainability issue |
| SECURITY_HOTSPOT | 🔒 | Security-sensitive code to review |
Always clean up temporary files after execution:
T="${TMPDIR:-/tmp}"
rm -f "$T/fetch_sonar.sh" "$T/sonar_pr_$PR_NUMBER.json" "$T/sonar_analyze.js" "$T/sonar_analysis_$PR_NUMBER.json"
| Error | Cause | Action |
|---|---|---|
| Token not set | $SONARQUBE_TOKEN missing | Ask user to export token |
| 401 Unauthorized | Invalid or expired token | Request new token from SonarCloud |
| 404 Not Found | PR doesn't exist in SonarCloud | Verify PR number and project key |
"issues": [] in a successful response | No issues returned | Report clean PR, congratulate team |
| Empty body, error body, or non-zero exit | Analysis did not run | Report NOT RUN with the error, never a clean PR |
| >500 issues | Pagination limit reached | Warn about incomplete data, suggest filtering |
| Network error | API unreachable | Check internet connection, retry |
Create .sonarcloud.properties or add to CLAUDE.md:
# SonarCloud Configuration
SONAR_ORGANIZATION=your-org
SONAR_PROJECT_KEY=your-org_your-project
SONAR_EXCLUSIONS=**/*.test.ts,**/*.spec.ts,**/migrations/**
SONAR_COVERAGE_EXCLUSIONS=**/*.test.ts,src/test/**
SonarCloud API limits:
Tip: Cache results for repeated queries to same PR.
- name: SonarQube Analysis
run: |
export SONARQUBE_TOKEN=${{ secrets.SONAR_TOKEN }}
export SONAR_PROJECT_KEY="${{ secrets.SONAR_PROJECT }}"
claude -p "/sonarqube ${{ github.event.pull_request.number }}"
Call it from a script or a Git hook of your own (Claude Code has no pre-merge hook event):
#!/bin/bash
PR_NUMBER=$(gh pr view --json number -q .number)
claude -p "/sonarqube $PR_NUMBER"
Never:
Always:
The flags below are extension ideas. This skill does not implement them; add the filtering to the analysis script before relying on them.
# Only show critical/blocker issues
/sonarqube 123 --severity BLOCKER,CRITICAL
# Only show bugs and vulnerabilities
/sonarqube 123 --types BUG,VULNERABILITY
# Specific file pattern
/sonarqube 123 --files "src/services/**"
# Compare issues across PRs
/sonarqube 123,124,125 --compare
Cause: Invalid or missing token
Fix:
# Regenerate token in SonarCloud
# Export new token
export SONARQUBE_TOKEN="new_token_here"
Cause: Analysis not yet complete or PR not analyzed
Fix: Wait for SonarCloud analysis to complete (~2-5 minutes after PR creation)
Cause: Wrong project key
Fix: Verify project key in SonarCloud URL:
https://sonarcloud.io/project/overview?id=YOUR_PROJECT_KEY
# Basic usage
/sonarqube 170
# With PR prefix
/sonarqube PR #234
# Using PR URL
/sonarqube https://github.com/org/repo/pull/170
# Custom severity filter (not implemented, see Advanced usage)
/sonarqube 170 --critical-only
PR Number: $ARGUMENTS
What SKILL.md sets; muted values are Claude Code's defaults
Use when running SonarQube analysis or interpreting SonarQube findings.
mediumThree short reads, in order
18 skills in this plugin
/ast-grep-patternsStructural code search and refactoring with ast-grep: choose it over Grep, then write tested pattern and YAML rule recipes. Use when renaming calls or changing an API signature across a large codebase, migrating a framework, or finding code by shape (async functions without try/catch, empty catch blocks, long parameter lists). Not for plain text searches, which Grep handles faster./audit-codebaseCodebase health audit scoring 7 categories with progression plan/check-cache-bugsAudit Claude Code setup for cache bugs (CC#40524): sentinel, --resume/--continue, attribution header + ArkNill B3/B4/B5/design-patternsDetect, suggest, and evaluate GoF design patterns in TypeScript/JavaScript codebases. Use when refactoring code, applying singleton/factory/observer/strategy patterns, reviewing pattern quality, or finding stack-native alternatives for React, Angular, NestJS, and Vue./diagnoseInteractive troubleshooting assistant for Claude Code issues/eval-skillsAudit a project or library of skills for metadata, trigger boundaries, workflow completion criteria, local resource closure, instruction economy, tool scope, effort, and routing evidence. Use before shipping skills, after importing a skill collection, or when a skill triggers too often or not at all.npx claudepluginhub florianbruniaux/claude-code-plugins --plugin code-qualityOther plugins' skills for the same job