Bring your own hook: a 5-line PostToolUse template calling sonar analyze agentic
Blog post from Sonar
SonarQube’s `sonar analyze agentic` command can be connected to Claude Code through a custom PostToolUse hook that analyzes files after Edit or Write actions and returns server-side, CI-contextual findings from SonarQube Cloud’s Vortex Agentic Analysis. The setup requires an authenticated SonarQube CLI, a Vortex-enabled Cloud project with a prior long-lived-branch CI analysis, and `jq` to parse Claude Code’s event JSON; the hook extracts the edited file path, runs deep analysis for that file, and sends detected issues back to Claude through stderr and exit code 2, prompting an automated fix-and-reanalyze loop. Deep mode enables cross-file capabilities such as taint analysis while comparing the edited file against context restored from the last CI scan, and the analysis command uses exit code 51 for findings and 0 for clean results. The minimal hook fails open on unexpected command failures, while an expanded version can limit analysis to selected source extensions and fail closed by surfacing authentication or service errors to Claude. Findings can alternatively be supplied as advisory JSON context without interrupting the turn, subject to output-size limits. The post also describes testing the integration with an intentionally unsafe SQL query, using the command independently for troubleshooting, adding a separate Bash pre-tool hook to block Git commits with open blocker issues, and choosing `sonar integrate claude` when default managed hooks are sufficient instead of requiring custom file scope, blocking behavior, or repository-managed configuration.
| Trend | Post Mentions | Total Month Mentions | Posts | Companies | MoM |
|---|---|---|---|---|---|
| Secrets Management | 2 | 2,244 | 480 | 132 | -13% |
| LLM | 1 | 5,068 | 1,020 | 229 | -34% |
Use this post, company, and trend context to find content marketing opportunities, perform competitive analysis, or address product feature gaps via the Plushcap MCP server or the Plushcap API.