When the sonarqube-cli runs an analysis (e.g. triggered automatically via the Claude Code agent plugin), it creates a .sonar/ scratch directory inside the project root. After the analysis completes, this directory is left behind even though it is empty.
In an AI-agent context where analyses are triggered repeatedly (e.g. after each file edit with Agentic Analysis enabled), these directories accumulate quickly across all analyzed projects.
Steps to reproduce
Install the sonarqube-agent-plugins for Claude Code (/sonarqube:sonar-integrate)
Let the agent run an analysis (e.g. via /sonarqube:sonar-analyze)
Check the project root after the analysis completes
Expected behavior
The .sonar/ scratch directory is removed after the analysis, or not created in the project directory in the first place.
Actual behavior
An empty .sonar/ directory remains in the project root after every analysis run.
Workaround
We added a custom Claude Code PostToolUse hook that removes empty .sonar/ directories after each tool invocation. But this workaround is not working on every OS so this should ideally be part of the official plugin rather than a manual workaround.
Thank you for the fast response and your help.
No, SONAR_USER_HOME is not set, so we’re using the default ~/.sonar. Running sonar system status shows logs under ~/.sonar/sonarqube-cli/.
I’m on version 1.2.0 (sonar --version).
I dug a bit deeper and can reliably reproduce it:
echo '{"prompt":"test","cwd":"'"$(pwd)"'"}' | sonar hook claude-prompt-submit
ls -la .sonar
# → empty .sonar/ directory created immediately
Same result with sonar hook claude-pre-tool-use. Both are called by the secret-scan hooks that sonar integrate claude installs (on every UserPromptSubmit and PreToolUse event respectively), so in an active agent session this fires constantly and leaves a fresh empty directory behind every time.
Hi @maksim.grebeniuk, just wanted to check in on this one — really appreciate that a fix was already found, but it looks like it hasn’t made it out yet. I’m still seeing the exact same behavior about two months later.
Versions on my end: sonarqube-cli 1.6.0, sonarqube-agent-plugins (Claude Code plugin) 2.6.0.
Same symptom as the original report: empty .sonar/ directories keep showing up in all kinds of working directories — not just the project root, but also unrelated subfolders I simply cd’d into or ran a script against, and even in Claude Code’s subagent task temp directories across completely different repos. It lines up with the sonar hook claude-pre-tool-use path that Claude Code’s global PreToolUse hook calls before every Bash command — it just picks up whatever cwd the process happens to be in at that moment, and each one ends up with its own leftover empty .sonar/.
For what it’s worth, the real cache under ~/.sonar/sonarqube-cli/ (bin/logs/telemetry/state.json) looks completely fine and correctly scoped — this is only about the extra per-invocation scratch folders.
Would it be possible to get an update on whether the fix actually shipped, and if so in which CLI version? It doesn’t seem to have landed by 1.6.0 yet. No rush, just flagging that it’s still adding up in agentic workflows that run a lot of Bash commands per session. Thanks for looking into it originally!