Code Hardcode Audit
When to Use This Skill
Use this skill when the user mentions:
- "hardcoded values", "hardcodes", "magic numbers"
- "constant detection", "find constants"
- "duplicate constants", "DRY violations"
- "code audit", "hardcode audit"
- "PLR2004", "semgrep", "jscpd", "gitleaks"
- "secret scanning", "leaked secrets", "API keys"
- "passwords in code", "credential leaks"
Quick Start
# Full audit (all tools, both outputs)
uv run --script scripts/audit_hardcodes.py -- src/
# Python magic numbers only (fastest)
uv run --script scripts/run_ruff_plr.py -- src/
# Pattern-based detection (URLs, ports, paths)
uv run --script scripts/run_semgrep.py -- src/
# Copy-paste detection
uv run --script scripts/run_jscpd.py -- src/
# Secret scanning (API keys, tokens, passwords)
uv run --script scripts/run_gitleaks.py -- src/
Tool Overview
| Tool |
Detection Focus |
Language Support |
Speed |
| Ruff PLR2004 |
Magic value comparisons |
Python |
Fast |
| Semgrep |
URLs, ports, paths, credentials |
Multi-language |
Medium |
| jscpd |
Duplicate code blocks |
Multi-language |
Slow |
| gitleaks |
Secrets, API keys, passwords |
Any (file-based) |
Fast |
Output Formats
JSON (--output json)
{
"summary": {
"total_findings": 42,
"by_tool": { "ruff": 15, "semgrep": 20, "jscpd": 7 },
"by_severity": { "high": 5, "medium": 25, "low": 12 }
},
"findings": [
{
"id": "MAGIC-001",
"tool": "ruff",
"rule": "PLR2004",
"file": "src/config.py",
"line": 42,
"column": 8,
"message": "Magic value used in comparison: 8123",
"severity": "medium",
"suggested_fix": "Extract to named constant"
}
],
"refactoring_plan": [
{
"priority": 1,
"action": "Create constants/ports.py",
"finding_ids": ["MAGIC-001", "MAGIC-003"]
}
]
}
Compiler-like Text (--output text)
src/config.py:42:8: PLR2004 Magic value used in comparison: 8123 [ruff]
src/probe.py:15:1: hardcoded-url Hardcoded URL detected [semgrep]
src/client.py:20-35: Clone detected (16 lines, 95% similarity) [jscpd]
Summary: 42 findings (ruff: 15, semgrep: 20, jscpd: 7)
CLI Options
--output {json,text,both} Output format (default: both)
--tools {all,ruff,semgrep,jscpd,gitleaks} Tools to run (default: all)
--severity {all,high,medium,low} Filter by severity (default: all)
--exclude PATTERN Glob pattern to exclude (repeatable)
--parallel Run tools in parallel (default: true)
References
Related
- ADR-0046: Semantic Constants Abstraction
- ADR-0047: Code Hardcode Audit Skill
code-clone-assistant - PMD CPD-based clone detection (DRY focus)
1---
2name: code-hardcode-audit
3description: Detect hardcoded values, magic numbers, and leaked secrets. TRIGGERS - hardcode audit, magic numbers, PLR2004, secret scanning.
4allowed-tools: Bash, Read, Write, Glob, Grep
5metadata:
6 source: https://skillmd.com/skills/aibot88/code-hardcode-audit
7---
8
9# Code Hardcode Audit
10
11## When to Use This Skill
12
13Use this skill when the user mentions:
14
15- "hardcoded values", "hardcodes", "magic numbers"
16- "constant detection", "find constants"
17- "duplicate constants", "DRY violations"
18- "code audit", "hardcode audit"
19- "PLR2004", "semgrep", "jscpd", "gitleaks"
20- "secret scanning", "leaked secrets", "API keys"
21- "passwords in code", "credential leaks"
22
23## Quick Start
24
25```bash
26# Full audit (all tools, both outputs)
27uv run --script scripts/audit_hardcodes.py -- src/
28
29# Python magic numbers only (fastest)
30uv run --script scripts/run_ruff_plr.py -- src/
31
32# Pattern-based detection (URLs, ports, paths)
33uv run --script scripts/run_semgrep.py -- src/
34
35# Copy-paste detection
36uv run --script scripts/run_jscpd.py -- src/
37
38# Secret scanning (API keys, tokens, passwords)
39uv run --script scripts/run_gitleaks.py -- src/
40```
41
42## Tool Overview
43
44| Tool | Detection Focus | Language Support | Speed |
45| ---------------- | ------------------------------- | ---------------- | ------ |
46| **Ruff PLR2004** | Magic value comparisons | Python | Fast |
47| **Semgrep** | URLs, ports, paths, credentials | Multi-language | Medium |
48| **jscpd** | Duplicate code blocks | Multi-language | Slow |
49| **gitleaks** | Secrets, API keys, passwords | Any (file-based) | Fast |
50
51## Output Formats
52
53### JSON (--output json)
54
55```json
56{
57 "summary": {
58 "total_findings": 42,
59 "by_tool": { "ruff": 15, "semgrep": 20, "jscpd": 7 },
60 "by_severity": { "high": 5, "medium": 25, "low": 12 }
61 },
62 "findings": [
63 {
64 "id": "MAGIC-001",
65 "tool": "ruff",
66 "rule": "PLR2004",
67 "file": "src/config.py",
68 "line": 42,
69 "column": 8,
70 "message": "Magic value used in comparison: 8123",
71 "severity": "medium",
72 "suggested_fix": "Extract to named constant"
73 }
74 ],
75 "refactoring_plan": [
76 {
77 "priority": 1,
78 "action": "Create constants/ports.py",
79 "finding_ids": ["MAGIC-001", "MAGIC-003"]
80 }
81 ]
82}
83```
84
85### Compiler-like Text (--output text)
86
87```
88src/config.py:42:8: PLR2004 Magic value used in comparison: 8123 [ruff]
89src/probe.py:15:1: hardcoded-url Hardcoded URL detected [semgrep]
90src/client.py:20-35: Clone detected (16 lines, 95% similarity) [jscpd]
91
92Summary: 42 findings (ruff: 15, semgrep: 20, jscpd: 7)
93```
94
95## CLI Options
96
97```
98--output {json,text,both} Output format (default: both)
99--tools {all,ruff,semgrep,jscpd,gitleaks} Tools to run (default: all)
100--severity {all,high,medium,low} Filter by severity (default: all)
101--exclude PATTERN Glob pattern to exclude (repeatable)
102--parallel Run tools in parallel (default: true)
103```
104
105## References
106
107- [Tool Comparison](./references/tool-comparison.md) - Detailed tool capabilities
108- [Output Schema](./references/output-schema.md) - JSON schema specification
109- [Troubleshooting](./references/troubleshooting.md) - Common issues and fixes
110
111## Related
112
113- ADR-0046: Semantic Constants Abstraction
114- ADR-0047: Code Hardcode Audit Skill
115- `code-clone-assistant` - PMD CPD-based clone detection (DRY focus)