Knots
A fast multi-language code complexity analyzer built on tree-sitter. Knots measures traditional complexity metrics alongside two AI-specific cost scores — AIRD (AI Reasoning Difficulty) and AICP (AI Context Pressure) — to identify which functions are genuinely expensive to modify with AI assistance.
Features
- Multiple Complexity Metrics: McCabe, Cognitive, Nesting Depth, SLOC, ABC, Test Scoring
- AI Cost Metrics: AIRD (reasoning difficulty) and AICP (context pressure) — corpus-validated against 32,205 functions across 6 open-source C codebases
- Multi-Language: C, C++, Rust, Python, JavaScript, TypeScript, Ada, Go, Java, C#, Kotlin, Swift, PHP, Fortran, Scala, and Lua — same metrics and thresholds across all supported languages
- Testability Matrix: Categorize functions by complexity and testability
- Multiple Output Formats: text, SARIF, JSON, NDJSON (find/xargs-composable), CSV
- CI Threshold Enforcement: exit 1 on any threshold violation; recommended
--aird-threshold 85 - Pre-commit Hook: native integration, no shim scripts required
- Validated: McCabe matches pmccabe exactly; Cognitive matches Mozilla rust-code-analysis at 1.004× mean ratio (11,365 Rust functions)
Installation
Prebuilt binary from PyPI (no Rust toolchain, installs in seconds):
pipx install knots # or: uv tool install knots
From crates.io:
cargo install knots
Or from source:
git clone https://github.com/brandon-arrendondo/knots.git
cd knots
cargo build --release
No C compiler or build system required.
Quick Start
# Single file
knots src/main.c
# Recursive directory
knots -r src/
# CI gate — fail if any function has AIRD > 85
knots -r src/ --aird-threshold 85
# Adopt the gate on a legacy codebase: snapshot today, then fail only on regressions
knots -r src/ --aird-threshold 85 --baseline .knots-baseline.json --write-baseline
knots -r src/ --aird-threshold 85 --baseline .knots-baseline.json
# Gate only the functions you actually touched (no new debt in this change)
knots -r src/ --aird-threshold 85 --changed
# SARIF for GitHub Code Scanning
knots -r --format sarif src/ > knots.sarif
# Corpus analysis — one JSON record per function
find . -name "*.c" -o -name "*.rs" | xargs knots --format ndjson > metrics.ndjson
# Testability matrix
knots -m src/main.c
Complexity Indicators
Based on max(McCabe, cognitive):
| Range | Indicator | Meaning |
|---|---|---|
| 1–10 | 😊 Good | Low complexity, easy to maintain |
| 11–20 | 😐 Okay | Moderate complexity, monitor |
| 21–49 | 😠 Bad | High complexity, consider refactoring |
| 50+ | 😢 Critical | Urgent refactoring needed |
Command-Line Options
knots [OPTIONS] [FILE]...
knots [OPTIONS] --compile-commands <FILE>
Options:
-r, --recursive Recursively process all supported source files in directories
-v, --verbose Show detailed per-function analysis
-m, --matrix Show testability matrix categorization
--compile-commands <FILE> Use compile_commands.json to get file list
--include <FILE> Include filter rules from JSON file (whitelist)
--exclude <FILE> Exclude filter rules from JSON file (blacklist)
--exclude-path <PATTERN> Exclude files whose path matches this regex (repeatable)
--format <FORMAT> text (default) | sarif | json | ndjson | csv
--mccabe-threshold <N> Exit 1 if any function exceeds this McCabe complexity
--cognitive-threshold <N> Exit 1 if any function exceeds this cognitive complexity
--nesting-threshold <N> Exit 1 if any function exceeds this nesting depth
--sloc-threshold <N> Exit 1 if any function exceeds this SLOC count
--abc-threshold <F> Exit 1 if any function exceeds this ABC magnitude
--return-threshold <N> Exit 1 if any function exceeds this return count
--aird-threshold <N> Exit 1 if any function exceeds this AIRD (AI Reasoning Difficulty) score (recommended: 85)
--aicp-threshold <N> Exit 1 if any function exceeds this AICP (AI Context Pressure) score
--external-calls-threshold <N> Exit 1 if any function exceeds this external call count
--unreachable-blocks-threshold <N> Exit 1 if any function has more than this many unreachable (dead-code) basic blocks (C/C++/Rust only)
--report <FILE> Write a detailed per-function report to this file (opt-in)
--baseline <FILE> Ratchet mode: gate only on regressions vs. this snapshot (see docs/baseline.rst)
--write-baseline Snapshot current scores to --baseline and exit without gating
--since <REF> Gate only functions overlapping lines changed since this git ref
--changed Gate only functions changed in the working tree (sugar for --since HEAD)
--explain <METRIC> Explain a metric (e.g. aird, aicp) and how to lower it, then exit
--find-duplicates Report structurally duplicated functions across the corpus (--recursive only)
--include-fixture-pairs Keep tests/pass vs tests/fail fixture pairs in --find-duplicates output (excluded by default)
--include-trivial-duplicates Keep small-body, low-repeat groups (getters, one-assert tests) in --find-duplicates output (excluded by default)
--dump-duplicates <FILE> Write a JSON snapshot of --find-duplicates results, for later comparison via --diff-duplicates
--diff-duplicates <BEFORE> <AFTER> Compare two --dump-duplicates snapshots and summarize resolved/new/shrank/grew groups; exits without needing corpus files
-j, --jobs <N> Parallel analysis threads (0 = auto-detect, 1 = sequential, default: 0)
-h, --help Print help
-V, --version Print version
Documentation
Full documentation is in the docs/ directory (Sphinx/RST):
- Installation
- Quick Start & Usage Examples
- CLI Reference
- Metrics Reference — AIRD/AICP formulas, corpus validation
- Output Formats — JSON schema, SARIF, NDJSON corpus patterns
- CI Integration — GitHub Actions, pre-commit hook
- Baseline / Ratchet Mode — adopt the gate on legacy code, fail only on regressions
- Filter Rules —
--include/--excludewhitelists/blacklists - knots.toml & Inline Suppression — TOML thresholds/exclusion,
tools:off/tools:suppresscomments - Test Quality Analysis — knots-test-complexity companion tool
- Alternatives Comparison — vs. lizard, rust-code-analysis, clippy; cognitive algorithm differences
- Troubleshooting
License
MIT
Metadata
Release files for knots 1.18.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| knots-1.18.0.tar.gz | 209.8 kB | With provenance | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| knots-1.18.0-py3-none-win_amd64.whl | Python 3 | none | Windows x86-64 | Details |
| knots-1.18.0-py3-none-musllinux_1_2_x86_64.whl | Python 3 | none | Linux musl 1.2+ x86-64 | Details |
| knots-1.18.0-py3-none-musllinux_1_2_aarch64.whl | Python 3 | none | Linux musl 1.2+ ARM64 | Details |
| knots-1.18.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | Python 3 | none | Linux glibc 2.17+ x86-64 | Details |
| knots-1.18.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | Python 3 | none | Linux glibc 2.17+ ARM64 | Details |
| knots-1.18.0-py3-none-macosx_11_0_arm64.whl | Python 3 | none | macOS 11.0+ ARM64 | Details |
| knots-1.18.0-py3-none-macosx_10_12_x86_64.whl | Python 3 | none | macOS 10.12+ x86-64 | Details |
Total release size: 37.4 MB
Release files / knots-1.18.0.tar.gz
| Download URL | knots-1.18.0.tar.gz |
|---|---|
| Size | 209.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3a55ee5c4b260e584002d89570f6392d48f3d01496f6691cb280b00b22dc2068
|
|
BLAKE2b-256 checksum How to use checksums |
a317cb1e0eaad7e00bfb9f744a64532580f762c876944b9ce6b5f343c9d0fa0d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.
Transparency logRelease files / knots-1.18.0-py3-none-win_amd64.whl
| Download URL | knots-1.18.0-py3-none-win_amd64.whl |
|---|---|
| Size | 5.0 MB |
| Tags | Python 3 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
d92cfeacb0c77f3f8609e5e80b94c219b4a0b23a9b49095279fa26f140b041ef
|
|
BLAKE2b-256 checksum How to use checksums |
048fb78036809669f13c347e51e655e5fa2aba2a23d23c8a0975ea7f7a16140a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.
Transparency logRelease files / knots-1.18.0-py3-none-musllinux_1_2_x86_64.whl
| Download URL | knots-1.18.0-py3-none-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 5.5 MB |
| Tags | Linux musl 1.2+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
4c38e48e79486f38988fce46f0b73d2899ffc49c165d4b4599812d5d31d84e09
|
|
BLAKE2b-256 checksum How to use checksums |
5de962ca3519f1264eaf1352bbc7c2e511ccdcf3c344f8c8e5de2c85147188fc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.
Transparency logRelease files / knots-1.18.0-py3-none-musllinux_1_2_aarch64.whl
| Download URL | knots-1.18.0-py3-none-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 5.3 MB |
| Tags | Linux musl 1.2+ ARM64 Python 3 |
|
SHA-256 checksum How to use checksums |
9f3a5be043ff4de1498b29f9de4c2507d7e013614345a126dc8e54dde5ff09af
|
|
BLAKE2b-256 checksum How to use checksums |
0ab6ffd709e1cc10e16eb434f3aa3b2ed4065d901ff56a20b14766934af93ff7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.
Transparency logRelease files / knots-1.18.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | knots-1.18.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 5.4 MB |
| Tags | Linux glibc 2.17+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
c1917e1b44cd454e1dbb5462c07bdf84162f3f8b185332a2da531032456d5f8a
|
|
BLAKE2b-256 checksum How to use checksums |
4bcd96a50ac3825a132689ba87e3dc5386d1faa37286ca6dd182d81b574cae55
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.
Transparency logRelease files / knots-1.18.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | knots-1.18.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 5.4 MB |
| Tags | Linux glibc 2.17+ ARM64 Python 3 |
|
SHA-256 checksum How to use checksums |
9acdb3296818e8514d88bd57bced4af51052793c2cb20f9be229d3f2787ce173
|
|
BLAKE2b-256 checksum How to use checksums |
df66c0a0afb623e8b8b6a095195e0d63efe81797d7e1016b05fe4549029ca810
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.
Transparency logRelease files / knots-1.18.0-py3-none-macosx_11_0_arm64.whl
| Download URL | knots-1.18.0-py3-none-macosx_11_0_arm64.whl |
|---|---|
| Size | 5.4 MB |
| Tags | Python 3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
dbaecbdce5907bcbabf7e8d07387a9d039203df33800ae349d21a6a212473c7b
|
|
BLAKE2b-256 checksum How to use checksums |
d7b15a66656577a43ca3f18f27b1a699a41ad8ca780b5520e577194e2b2224e6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.
Transparency logRelease files / knots-1.18.0-py3-none-macosx_10_12_x86_64.whl
| Download URL | knots-1.18.0-py3-none-macosx_10_12_x86_64.whl |
|---|---|
| Size | 5.2 MB |
| Tags | Python 3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
d993261221e2704ac66b5295976cbaae27bef831fdcfe279a7865cc09c4d6af1
|
|
BLAKE2b-256 checksum How to use checksums |
6d97b50a3771291b675e959c673f2c5b1a879702f3bba3bc87c302be0a87bed9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.
Transparency logSecurity for knots 1.18.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 8 files in this release have been uploaded with provenance metadata.
Attestation for knots-1.18.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.