static-analysis — Claude Code skill: what it does, how to install
Guides static analysis configuration for C and C++ projects using clang-tidy, cppcheck, and scan-build. It helps filter warnings and triage false positives.
npx skills add mohitmishra786/low-level-dev-skills --skill static-analysis -a claude-codeWhat static-analysis does
The skill provides workflows for running static analysis engines across C and C++ codebases. It contains configuration samples for .clang-tidy and a workflow step for GitHub Actions. A decision tree classifies checks by objective. This structure separates safety checks like cert-* from syntax updates in modernize-*.
Full repository scans with clang-tidy require a compile_commands.json database. Without this file, whole-project diagnostics fail. The skill covers generating this database via -DCMAKE_EXPORT_COMPILE_COMMANDS=ON in CMake or using bear and compiledb for Make-based trees. It also details precise noise reduction using inline NOLINT comments, [[clang::suppress]] attributes, or directory exclusions in HeaderFilterRegex.
Path-sensitive defects are handled by scan-build. It intercepts Make or CMake builds to detect null pointer dereferences and memory leaks across functions, rendering results into an HTML view.
What it helps with
- generate
compile_commands.jsonfor CMake and Make builds - configure check categories and automated fixes in
clang-tidy - silence false positives using
NOLINTcomments and header filters - integrate
cppcheckandrun-clang-tidyinto GitHub Actions - run path-sensitive bug detection using
scan-build
Example prompts for the agent
- Set up a .clang-tidy configuration targeting bugprone and modernize checks
- How do I generate compile_commands.json and run run-clang-tidy on my build?
- Suppress a false positive warning from cppcheck in my C++ source file
How to install static-analysis
1Skills CLI (Vercel)
npx skills add mohitmishra786/low-level-dev-skills --skill static-analysis -a claude-code2Manually: put the files in place
~/.claude/skills/static-analysis/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/static-analysis/
1Skills CLI (Vercel)
npx skills add mohitmishra786/low-level-dev-skills --skill static-analysis -a codex2Manually: put the files in place
.agents/skills/static-analysis/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add mohitmishra786/low-level-dev-skills --skill static-analysis -a cursor2Manually: put the files in place
.cursor/skills/static-analysis/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install mohitmishra786/low-level-dev-skills static-analysis2Manually: put the files in place
.github/skills/static-analysis/SKILL.md1Skills CLI (Vercel)
npx skills add mohitmishra786/low-level-dev-skills --skill static-analysis -a gemini-cli2Platform CLI
gemini skills install https://github.com/mohitmishra786/low-level-dev-skills --path skills/build-systems/static-analysisManually: put the files in place
.devin/skills/static-analysis/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add mohitmishra786/low-level-dev-skills --skill static-analysis -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about static-analysis
How to install static-analysis in Claude Code?
Run npx skills add mohitmishra786/low-level-dev-skills --skill static-analysis -a claude-code in your terminal.
What does static-analysis do?
It guides agents in selecting, running, and tuning clang-tidy, cppcheck, and scan-build on C and C++ repositories. It provides configuration templates, suppression patterns, and CI steps.
What is required before running clang-tidy across a repository?
You need a compile_commands.json compilation database at the project root. For CMake projects, generate it by setting -DCMAKE_EXPORT_COMPILE_COMMANDS=ON, or use bear or compiledb when building with Make.
Source text
SKILL.md · MIT
---
name: static-analysis
description: Static analysis skill for C/C++ codebases. Use when hardening code quality, triaging noisy builds, running clang-tidy, cppcheck, or scan-build, interpreting check categories, suppressing false positives, or integrating static analysis into CI. Activates on queries about clang-tidy checks, cppcheck, scan-build, compile_commands.json, code hardening, or static analysis warnings.
---
# Static Analysis
## Purpose
Guide agents through selecting, running, and triaging static analysis tools for C/C++ — clang-tidy, cppcheck, and scan-build — including suppression strategies and CI integration.
## Triggers
- "How do I run clang-tidy on my project?"
- "What clang-tidy checks should I enable?"
- "cppcheck is reporting false positives — how do I suppress them?"
- "How do I set up scan-build for deeper analysis?"
- "My build is noisy with static analysis warnings"
- "How do I generate compile_commands.json for clang-tidy?"
## Workflow
### 1. Generate compile_commands.json
clang-tidy requires a compilation database:
```bash
# CMake (preferred)
cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
ln -s build/compile_commands.json .
# Bear (for Make-based projects)
bear -- make
# compiledb (alternative for Make)
pip install compiledb
compiledb make
```
### 2. Run clang-tidy
```bash
# Single file
clang-tidy src/foo.c -- -std=c11 -I include/
# Whole project via compile_commands.json
run-clang-tidy -p build/ -j$(nproc)
# With specific checks enabled
clang-tidy -checks='bugprone-*,modernize-*,performance-*' src/foo.cpp
# Apply auto-fixes
clang-tidy -checks='modernize-use-nullptr' -fix src/foo.cpp
```
### 3. Check category decision tree
```text
Goal?
├── Find real bugs → bugprone-*, clang-analyzer-*
├── Modernise C++ code → modernize-*
├── Follow core guidelines → cppcoreguidelines-*
├── Catch performance issues → performance-*
├── Security hardening → cert-*, hicpp-*
└── Readability / style → readability-*, llvm-*
```
| Category | Key checks | What it catches |
|----------|-----------|-----------------|
| `bugprone-*` | `use-after-move`, `integer-division`, `suspicious-memset-usage` | Likely bugs |
| `modernize-*` | `use-nullptr`, `use-override`, `use-auto` | C++11/14/17 idioms |
| `cppcoreguidelines-*` | `avoid-goto`, `pro-bounds-*`, `no-malloc` | C++ Core Guidelines |
| `performance-*` | `unnecessary-copy-initialization`, `avoid-endl` | Performance regressions |
| `clang-analyzer-*` | `core.*`, `unix.*`, `security.*` | Path-sensitive bugs |
| `cert-*` | `err34-c`, `str51-cpp` | CERT coding standard |
### 4. .clang-tidy configuration file
```yaml
# .clang-tidy — place at project root
Checks: >
bugprone-*,
modernize-*,
performance-*,
-modernize-use-trailing-return-type,
-bugprone-easily-swappable-parameters
WarningsAsErrors: 'bugprone-*,clang-analyzer-*'
HeaderFilterRegex: '^(src|include)/.*'
CheckOptions:
- key: modernize-loop-convert.MinConfidence
value: reasonable
- key: readability-identifier-naming.VariableCase
value: camelCase
```
### 5. Suppress false positives
```cpp
// Suppress a single line
int result = riskyOp(); // NOLINT(bugprone-signed-char-misuse)
// Suppress a block
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
constexpr int BUFFER_SIZE = 4096;
// Suppress whole function
[[clang::suppress("bugprone-*")]]
void legacy_code() { /* ... */ }
```
Or in `.clang-tidy`:
```yaml
# Exclude third-party directories
HeaderFilterRegex: '^(src|include)/.*'
# Disable specific checks
Checks: '-bugprone-easily-swappable-parameters'
```
### 6. Run cppcheck
```bash
# Basic run
cppcheck --enable=all --std=c11 src/
# With compile_commands.json
cppcheck --project=build/compile_commands.json
# Include specific checks and suppress noise
cppcheck --enable=warning,performance,portability \
--suppress=missingIncludeSystem \
--suppress=unmatchedSuppression \
--error-exitcode=1 \
src/
# Generate XML report for CI
cppcheck --xml --xml-version=2 src/ 2> cppcheck-report.xml
```
| `--enable=` value | What it checks |
|-------------------|----------------|
| `warning` | Undefined behaviour, bad practices |
| `performance` | Redundant operations, inefficient patterns |
| `portability` | Non-portable constructs |
| `information` | Configuration and usage notes |
| `all` | Everything above |
### 7. Path-sensitive analysis with scan-build
```bash
# Intercept a Make build
scan-build make
# Intercept CMake build
scan-build cmake --build build/
# Show HTML report
scan-view /tmp/scan-build-*/
# With specific checkers
scan-build -enable-checker security.insecureAPI.gets \
-enable-checker alpha.unix.cstring.BufferOverlap \
make
```
scan-build finds deeper bugs than clang-tidy: use-after-free across functions, dead stores from logic errors, null dereferences on complex paths.
### 8. CI integration
```yaml
# GitHub Actions
- name: Static analysis
run: |
cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
run-clang-tidy -p build -j$(nproc) -warnings-as-errors '*'
- name: cppcheck
run: |
cppcheck --enable=warning,performance \
--suppress=missingIncludeSystem \
--error-exitcode=1 \
src/
```
For clang-tidy check details, see [references/clang-tidy-checks.md](references/clang-tidy-checks.md).
## Related skills
- Use `skills/compilers/clang` for Clang toolchain and diagnostic flags
- Use `skills/compilers/gcc` for GCC warnings as complementary analysis
- Use `skills/runtimes/sanitizers` for runtime bug detection alongside static analysis
- Use `skills/build-systems/cmake` for `CMAKE_EXPORT_COMPILE_COMMANDS` setup
© mohitmishra786 · MIT · mohitmishra786/low-level-dev-skills