Health Scorecard
codeknife score runs the static suite and condenses the result into one number from 0 to 100, a letter grade and six pillar scores. Use it to track code health over time: record a snapshot on each merge with --record, and the next run shows the change and a sparkline trend.
score is informational. It always exits 0, even for a grade of F. To fail a build, use The Check Gate.
Quick start
Section titled “Quick start”codeknife --no-cache --format human scoreCodeKnife Health Scorecard: 88.3/100 (Grade B+) | trend ▇ (n/a)Files: 8 | Code lines: 81 | Errors: 1 | Warnings: 5 | Info: 1 Architecture (25%) 78.4/100 [4 finding(s)] Security (25%) 78.2/100 [1 finding(s)] Reliability (15%) 94.6/100 [1 finding(s)] Dead & Deps (10%) 100.0/100 [0 finding(s)] Testing (15%) 100.0/100 [0 finding(s)] Docs & Churn (10%) 99.5/100 [1 finding(s)]The demo repository has one shell-injection error, four architecture warnings, one clone warning and one churn info finding. n/a means there is no recorded history yet.
| Flag | Default | Effect |
|---|---|---|
--record |
off | Append this run to .codeknife/history.jsonl. Ignored with --no-cache. |
--history N |
10 |
How many of the most recent history entries to load for the delta and sparkline. 0 is treated as 1. |
--coverage PATH |
none | Coverage report for CRAP findings. Without it, the first coverage.paths entry from codeknife.toml is used, or the tests blade looks for a report. A missing file is an error. See Coverage Reports. |
Global flags:
--stricttightens thresholds, so more findings and a lower score.--changed(with an optional--sincebase ref) scores only findings in changed files. File count and code lines still cover the whole repository.--no-cachewrites nothing to.codeknife/, including history. History is still read.--format:human,agent,markdownandjsoneach have their own layout.sarifprints the JSON form.
Findings in codeknife.baseline are removed before scoring, so a fully baselined repository scores as if it were clean. See Ratchet Baseline.
The formula
Section titled “The formula”1. Assign each finding to a pillar
Section titled “1. Assign each finding to a pillar”| Pillar | Weight | Blades |
|---|---|---|
| Architecture | 25% | arch |
| Security | 25% | sec, guard |
| Reliability | 15% | slop, clones |
| Dead & Deps | 10% | dead, deps |
| Testing | 15% | tests, mutate, blast |
| Docs & Churn | 10% | docs, comments, churn, map |
2. Add severity points
Section titled “2. Add severity points”| Severity | Points |
|---|---|
error |
14 |
warning |
4.5 |
info |
0.4 |
Every loosening reported by the Loosening Guard adds 30 points to Security and counts as one Security error and one overall error.
3. Score each pillar
Section titled “3. Score each pillar”kloc = max(1, code_lines / 1000)penalty = (points / kloc) × 1.2 + (errors_in_pillar / sqrt(kloc)) × 5pillar = clamp(100 - penalty, 0, 100), rounded to 1 decimalcode_lines is the sum of code lines over all scanned files. Penalties are spread over the repository size, so the same findings cost less in a larger repository. Below 1,000 code lines, kloc is 1.
4. Combine
Section titled “4. Combine”overall = sum(pillar × weight)if there is at least one error: overall = min(overall, 89.9)overall = clamp(overall, 0, 100), rounded to 1 decimalThe error cap means a repository with any error (including a loosening) can never get an A- or better.
Worked example (the run above, kloc = 1):
- Architecture: 4 warnings,
4 × 4.5 × 1.2 = 21.6, score78.4. - Security: 1 error,
14 × 1.2 + 1 × 5 = 21.8, score78.2. - Reliability: 1 warning,
5.4, score94.6. - Docs & Churn: 1 info,
0.48, score99.5. - Weighted sum
88.29, below the cap, rounded88.3.
5. Grade
Section titled “5. Grade”| Score at least | Grade |
|---|---|
| 97 | A+ |
| 93 | A |
| 90 | A- |
| 87 | B+ |
| 83 | B |
| 80 | B- |
| 75 | C+ |
| 70 | C |
| 60 | D |
| below 60 | F |
History and trends
Section titled “History and trends”--record appends one JSON line to .codeknife/history.jsonl in the repository root, creating the directory if needed:
{"timestamp":"2026-11-30T18:56:45Z","git_sha":"9a5a6a07c12f","overall":88.3,"grade":"B+","files":8,"errors":1,"warnings":5,"infos":1}| Field | Meaning |
|---|---|
timestamp |
UTC time, YYYY-MM-DDTHH:MM:SSZ |
git_sha |
First 12 characters of HEAD, or null outside a git repository |
overall, grade |
Score and grade |
files |
Files scanned |
errors, warnings, infos |
Finding counts (errors include loosenings) |
Pillar scores are not stored.
On every run, score reads the last --history entries (blank and unparseable lines are skipped), then:
deltais this run’s score minus the most recent entry’s score, rounded to 1 decimal. Without history it isn/ain text andnullin JSON.- The sparkline has one block per loaded entry plus one for this run. Each score maps to one of
▁▂▃▄▅▆▇█byround(score / 100 × 7).
The history is read before the new entry is written. A run with --record compares against the previous snapshot, not against itself.
Recording two snapshots
Section titled “Recording two snapshots”First snapshot, with the shell-injection error:
codeknife --format human score --recordCodeKnife Health Scorecard: 88.3/100 (Grade B+) | trend ▇ (n/a)...Remove shell=True, commit, and record again:
codeknife --format human score --recordCodeKnife Health Scorecard: 93.7/100 (Grade A) | trend ▇█ (+5.4)Files: 8 | Code lines: 81 | Errors: 0 | Warnings: 5 | Info: 1 Architecture (25%) 78.4/100 [4 finding(s)] Security (25%) 100.0/100 [0 finding(s)] Reliability (15%) 94.6/100 [1 finding(s)] Dead & Deps (10%) 100.0/100 [0 finding(s)] Testing (15%) 100.0/100 [0 finding(s)] Docs & Churn (10%) 99.5/100 [1 finding(s)]The history file now has two lines:
{"timestamp":"2026-11-30T18:56:45Z","git_sha":"9a5a6a07c12f","overall":88.3,"grade":"B+","files":8,"errors":1,"warnings":5,"infos":1}{"timestamp":"2026-11-30T18:56:57Z","git_sha":"a42e4f42677a","overall":93.7,"grade":"A","files":8,"errors":0,"warnings":5,"infos":1}A later run without --record shows both snapshots plus the current run:
codeknife --format human scoreCodeKnife Health Scorecard: 93.7/100 (Grade A) | trend ▇██ (+0.0)...Limiting the window to the last snapshot:
codeknife --format agent score --history 1CODEKNIFE score overall=93.7 grade=A delta=+0.0 spark=██ files=8 errors=0 warnings=5 infos=1 PILLAR Architecture weight=25% score=78.4 findings=4 PILLAR Security weight=25% score=100.0 findings=0 PILLAR Reliability weight=15% score=94.6 findings=1 PILLAR Dead & Deps weight=10% score=100.0 findings=0 PILLAR Testing weight=15% score=100.0 findings=0 PILLAR Docs & Churn weight=10% score=99.5 findings=1Output formats
Section titled “Output formats”Markdown, suitable for a pull request comment:
codeknife --no-cache --format markdown score## CodeKnife Health Scorecard — **88.3/100 (B+)**
Trend `▇` (n/a) | Files: 8 | Errors: 1 | Warnings: 5
| Pillar | Weight | Score | Findings || --- | ---: | ---: | ---: || Architecture | 25% | 78.4 | 4 || Security | 25% | 78.2 | 1 || Reliability | 15% | 94.6 | 1 || Dead & Deps | 10% | 100.0 | 0 || Testing | 15% | 100.0 | 0 || Docs & Churn | 10% | 99.5 | 1 |JSON:
codeknife --no-cache --format json score{ "overall": 88.3, "grade": "B+", "delta": null, "sparkline": "▇", "pillars": [ { "name": "Architecture", "weight": 0.25, "score": 78.4, "findings": 4 },... ], "files_scanned": 8, "code_lines": 81, "errors": 1, "warnings": 5, "infos": 1, "history": [], "recorded": false}| Field | Type | Meaning |
|---|---|---|
overall |
number | 0 to 100 |
grade |
string | Letter grade |
delta |
number or null | Change against the most recent loaded history entry |
sparkline |
string | One block per loaded entry plus this run |
pillars |
array | name, weight (0 to 1), score, findings |
files_scanned |
number | Files in the scan |
code_lines |
number | Code lines over all files |
errors, warnings, infos |
number | Counts after the baseline filter; errors include loosenings |
history |
array | The loaded history entries, oldest first |
recorded |
bool | true when this run was appended |
Rule IDs
Section titled “Rule IDs”score emits no findings and has no rule IDs of its own. It counts findings from every blade by blade and severity. See Rule Catalogue.
Exit codes
Section titled “Exit codes”| Code | When |
|---|---|
0 |
Score printed, at any score or grade |
2 |
CodeKnife error, for example a missing --coverage file or an unwritable history file |
Also available via
Section titled “Also available via”There is no MCP tool and no other command that computes the score. Only the codeknife score command does.