sonar

sonar is a command for Claude Code from LeeYudok/agents-scaffold. It costs 35 tokens per session (1,446 once invoked), scanned C, original, MIT.

A command for running SonarQube, a tool that examines source code for quality and security problems. It can show current results, rerun the analysis, inspect security hotspots, check test coverage, and explain quality-gate results.

In plain words
What is it for?
Use it to rescan a project, review security hotspots awaiting inspection, check how much code is covered by tests, view quality-gate conditions, or filter critical findings to a path.
Why use it?
It gathers code-quality information in one place instead of requiring developers to inspect the SonarQube service manually. It also checks whether the configured server and credentials are usable.

Command for Claude Code

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/leeyudok/agents-scaffold/sonar
Clone the repo
git clone --depth 1 https://github.com/LeeYudok/agents-scaffold

Made for: Claude Code.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for sonar

README.md
[![agentmods](https://agentmods.dev/badge/commands/leeyudok/agents-scaffold/sonar.svg)](https://agentmods.dev/commands/leeyudok/agents-scaffold/sonar)
Your own site
<a href="https://agentmods.dev/commands/leeyudok/agents-scaffold/sonar"><img src="https://agentmods.dev/badge/commands/leeyudok/agents-scaffold/sonar.svg" alt="Measured on agentmods" height="20"></a>
Per session 35 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,446 The whole file, excluding the scripts and references it only reads on demand.
Security scan C 2 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00035 $0.01446
Opus 5 $0.00017 $0.00723
Sonnet 5 $0.00007 $0.00289
Haiku 4.5 $0.00003 $0.00145

Measured 5d ago against content hash b2504a8b1cad, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade C, and why

sonar scanned grade C with 2 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 5d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Downloads and executes remote codehighSupply chain

curl | sh runs whatever the server returns today, which is not necessarily what it returned when this was reviewed.

status=$(curl -s -u "$token:" "http://localhost:9000/api/ce/task?id=$ceTaskId" | python3 -c "import sys,json; print(json.load(sys.stdin)['task']['status'])")

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

- **host 사전 리브니스 체크**: `curl -s -o /dev/null -w "%{http_code}" $host/api/system/status` → 200 아니면 properties 의 URL 이 죽은 주소(예: 방치된 `localhost:9000`)일 수 있음. 실제 서버 확인 후 `-Dsonar.host.url` 로 override.
.claude/commands/sonar.md · 100 lines

How it starts

The opening of the file, as written. The whole thing — 100 lines — stays where its author put it; the contents beside it link to each section on GitHub.

SonarQube 정적분석을 실행하고 결과를 요약한다.

인자 파싱

$ARGUMENTS 첫 단어가 서브커맨드. 없으면 현재 지표 요약.

서브커맨드 동작
(없음) 캐시된 현 지표 요약
rescan 스캐너 실행 + CE task 폴링 + 결과 요약
hotspots TO_REVIEW 보안 핫스팟 조회
coverage 커버리지 분석
qg Quality Gate 조건 breakdown
<path> 해당 경로 CRITICAL 이슈만 필터

API 접속

  • sonar-project.properties 에서 sonar.projectKeysonar.host.url 읽기
  • 토큰은 환경변수 우선SONAR_TOKEN(또는 프로젝트 .env). sonar-project.properties 에 토큰 저장 금지: 커밋되는 파일이라 git 히스토리로 유출된다. sonar.token 라인이 이미 있으면 rotate + env 이관 권고.
  • host 사전 리브니스 체크: curl -s -o /dev/null -w "%{http_code}" $host/api/system/status → 200 아니면 properties 의 URL 이 죽은 주소(예: 방치된 localhost:9000)일 수 있음. 실제 서버 확인 후 -Dsonar.host.url 로 override.
  • 인증: curl -u "$SONAR_TOKEN:" ... 또는 curl -H "Authorization: Bearer $SONAR_TOKEN" ...

토큰 2종 구분:

  • sqp_ Project Analysis Token → sonar-scanner 실행, 일반 조회
  • squ_ User Token → hotspot 상태 변경 등 관리 API (403 나면 이쪽으로)

서브커맨드 상세

기본 — 현 지표 요약

token="${SONAR_TOKEN:?SONAR_TOKEN 설정 필요 (sonar-project.properties 에서 읽지 말 것)}"
key=$(grep 'sonar.projectKey' sonar-project.properties | cut -d= -f2-)
curl -s -u "$token:" \
  "http://localhost:9000/api/measures/component?component=$key&metricKeys=bugs,vulnerabilities,code_smells,coverage,security_hotspots,duplicated_lines_density,ncloc"

표 형태로 출력: bugs / vulnerabilities / security_hotspots / code_smells / coverage / ncloc

rescan — 재스캔 + delta

  1. 서버 리브니스 체크 (API 접속 섹션 참조) — 스캐너 30초 hang 대신 조기 중단
  2. 현 수치 /tmp/sonar-before.json 저장
  3. 스캐너는 명시 override 로 실행 (낡은 properties 값이 스캔을 납치하지 못하게):
    sonar-scanner -Dsonar.host.url="$host" -Dsonar.token="$SONAR_TOKEN"
    
  4. CE task 폴링 (최대 90초, 2초 간격):
    for i in $(seq 1 45); do
      status=$(curl -s -u "$token:" "http://localhost:9000/api/ce/task?id=$ceTaskId" | python3 -c "import sys,json; print(json.load(sys.stdin)['task']['status'])")
      [ "$status" = "SUCCESS" ] && break
      [ "$status" = "FAILED" ] && { echo "task FAILED" >&2; break; }
      sleep 2
    done
    
  5. 분석 경고 확인 — CE task 응답의 warnings(대시보드 경고 배너와 동일). 인코딩 깨짐, sonar.python.version 미지정 등은 이슈 목록엔 절대 안 나오고 여기만 나온다. 인코딩 경고 시 오염 파일 탐지:
    grep -rlI $'\xef\xbf\xbd' <source-dirs>   # U+FFFD 치환문자 포함 파일
    
  6. 전/후 수치 delta 표시

Read the full file on GitHub · 100 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 5d ago First seen · 100 lines · 35 tokens per session scan C b2504a8b1cad

Subscribe to this mod's changes

sonar is a command published in the GitHub repository LeeYudok/agents-scaffold (25 stars, last pushed 6d ago), licensed MIT. It adds 35 tokens to every session and 1,446 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it C with 2 findings (downloads and executes remote code, makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.