Sonarqube-cli leaves behind empty .sonar scratch directories in project folder

Description

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

  1. Install the sonarqube-agent-plugins for Claude Code (/sonarqube:sonar-integrate)
  2. Let the agent run an analysis (e.g. via /sonarqube:sonar-analyze)
  3. 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.

Environment

  • OS: Windows 11
  • Agent: Claude Code
  • Plugin: sonarqube-agent-plugins v2.1.0

Hello @lpieprzyk ,

I don’t understand why this happens. Did you set the SONAR_USER_HOMEenvironment variable?

What version of the SonarQube CLI are you using?