Skip to content
Projects

About

Architecture linter for TypeScript and JavaScript code written by AI agents. Finds cycles, tangles, state leaks and prop drilling, grades the codebase A to F, and stops the agent at the next knot. Zero config, Claude Code Stop hook.

Developer Tools

How these counts are measured

Measured star growth

in 24h
0
in 7 days
Collecting history
in 15 days
Collecting history
in 1 month
Collecting history

Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.

README.md

Original

unknot

Architecture linter for TypeScript and JavaScript code written by AI agents.
Finds the structural knots no test and no file-level linter can see, grades the codebase from A to F,
and sends the agent back to work when a task ends with a new one.

npm version ci node version MIT license

Quick start · Leaderboard · Rules · Claude Code plugin · Agents · CI · Configuration

unknot reports a field leak, a module cycle and prop drilling with exact files and lines, then grades the project B

Why

An agent writes code that compiles and passes every test, and still ties the project into knots: folders that import each other, services that reach into each other's state, wrappers that wrap nothing, props carried through five components. ESLint checks one file at a time and tests check behaviour, so nothing fails. The cost shows up later, when every next change is harder than the last.

unknot reads the whole TypeScript or JavaScript project through the TypeScript compiler, builds the real dependency graph and reports each knot with the exact files, the lines and the direction of the fix. A cycle of fourteen folders becomes "remove these four imports".

Whole-project analysisType-aware, built on the TypeScript compiler. Erased type imports, lazy import() and handler slots are understood, so what is reported is real.
Zero configurationnpx unknot and nothing else. Layers are read from the code. Monorepos, project references, path aliases and plain JavaScript (with or without a jsconfig.json) work out of the box.
A grade from A to FOne grade and one number, the knot index, for the structure of a codebase, on the same scale as the leaderboard of popular AI repositories.
Built for agentsA Claude Code plugin with a Stop hook and skills, AGENTS.md rules for Codex and Cursor, and a CI step. The agent gets the report and goes back to fix it.
Fits an existing projectToday's knots are recorded as known debt. Only new ones fail.

Works with TypeScript, JavaScript, NestJS, Angular, React, Preact, Solid, Vue, Svelte and Astro.

Quick start

npx unknot            # report the knots
npx unknot --score    # grade the project from A to F
npx unknot init       # record today's debt and guard the code from now on

In Claude Code, one command guards every git repository: /plugin install unknot --marketplace PatternVoid/unknot.

unknot init does three things: writes today's knots to .unknot.allow as known debt, adds a Stop hook to Claude Code, and puts the rules for agents into CLAUDE.md when the project has one, otherwise into AGENTS.md. From then on, a turn that ends with a new knot is handed back to the agent with the report.

Requires Node 20.11 or newer. Nothing to install, nothing to configure.

The leaderboard

We ran unknot with zero configuration over 105 of the most starred TypeScript repositories of the AI ecosystem: 395,184 source files, 9,057 structural findings, every one published with its file and line. 125 repositories were scanned; the 105 with at least 200 source files are ranked.

Grade A B C D F
Repositories 8 11 23 28 35

The 15 most starred of them, and where each one stands:

Grade Repository Stars Files Knot index Rank
C morluto/rea 479k 3,293 32.1 34 of 105
B openclaw/openclaw 395k 27,273 18.1 9 of 105
C deepseek-ai/deepseek-harness 287k 3,753 29.7 28 of 105
F n8n-io/n8n 212k 15,575 52.9 81 of 105
D firecrawl/firecrawl 210k 274 44.4 63 of 105
F stablyai/orca 139k 30,118 55.0 85 of 105
A shadcn-ui/ui 129k 1,662 10.7 4 of 105
F thedotmack/claude-mem 120k 1,132 49.2 75 of 105
D paperclipai/paperclip 117k 6,280 46.0 66 of 105
D supabase/supabase 116k 6,867 38.0 47 of 105
F google-gemini/gemini-cli 109k 1,129 67.5 93 of 105
A Egonex-AI/Understand-Anything 95k 204 2.0 2 of 105
D OpenHands/OpenHands 94k 1,520 43.7 62 of 105
C koala73/worldmonitor 91k 1,347 33.4 37 of 105
C cheaper-inference/OmniRoute 90k 7,323 29.0 22 of 105

Cleanest of all: walkinglabs/learn-harness-engineering with a knot index of 0.0. Knottiest: teambit/bit at 128.5.

Full leaderboard: all 105 repositories, the method and every finding →

Grade your own

npx unknot --score
unknot score: B  knot index 24.7 (38 findings in 1808 files)

The number is the knot index. Every finding weighs by its rule (a folder cycle weighs 5 plus 0.5 for every folder beyond two; shared-state, wide-component and duplicate-type are reported and do not weigh in the grade yet); the weights are summed, divided by the file count plus 300 and multiplied by 1000. Lower is better: A up to 18, B up to 27, C up to 36, D up to 48, F above. A project under 50 source files is not graded.

npx unknot --badge prints a badge for your README:

[![unknot: B](https://img.shields.io/badge/unknot-B-green)](https://github.com/PatternVoid/unknot)

The rules

Rule What it finds
module-cycle Folders that import each other at runtime, directly or through a chain of folders. The finding puts them in layer order and names the few imports that go upward.
import-cycle Files that import each other in a loop no folder cycle explains: inside one module, or through a parent folder.
tangle Two classes in different files that use each other.
field-leak Another file assigns to a public field of a class with behaviour, or mutates the collection it holds.
shared-state A module-level object, array, Map or Set that two or more other files change.
shallow-module A file with 3 or more functions or methods that only pass their own arguments to another module, when they make up at least half of its functions or of a class's public methods; a class that creates the collaborator itself, only when all of them do.
wide-injection A class that takes more than 9 collaborators (services, not values) through its constructor or inject().
forward-ref forwardRef() that defers a reference to a provider or module in another file, in NestJS or Angular: the two cannot be loaded in order.
prop-drilling A prop that travels through 3 or more components that only hand it down.
wide-component A component or custom hook with more than 15 state hooks and effects.
duplicate-type A type, interface, union or enum with 4 or more members declared again, same name and same members, in another file of the package. Copies under migrations and copies whose paths differ only by a version folder (api/v1/user.dto.ts, api/v2/user.dto.ts) do not count.
wide-directory A directory with more than 40 source files and subdirectories. Migrations and ui kit folders (components/ui, registry/**/ui) do not count.
long-file A file with more than 1500 lines of code. Blank lines, comments, enums, data tables, dictionaries and template text are not counted.

npx unknot --list-rules prints them. npx unknot --explain <rule> says what a rule means and how to fix it from first principles.

One idea stands behind every rule: deep modules, narrow interfaces (John Ousterhout, A Philosophy of Software Design).

Precise by design. An import the compiler erases is not a dependency, and neither is a lazy import() or a require() inside a function; an awaited import() at the top of a module is one. A class named only in a type does not tangle. Reading a field is not a leak, and neither is assigning a callback slot such as onmessage. Binding a prop to a differently named event of a child (onClick={onKeep}) is using it, not drilling it. A dictionary with a few formatter functions is data, not a long file. A file or a class is shallow only when at least half of its functions or public methods pass through, and a class that constructs its collaborator itself with new only when every public method does. Value objects are not wide injections. Decorated controller methods, Next.js server actions and route handlers are not wrappers, and neither is a function that adds default values. An ORM entity whose only methods are lifecycle hooks is data: assigning its fields is not a leak. key and ref are React's, not a prop handed down. A parent folder and its children are one module. A module split into a state file and one file that writes it is not shared state. The same type in two packages that cannot import each other is not a duplicate.

Stack coverage

Stack Coverage
TypeScript, JavaScript every rule, type-aware through the TypeScript compiler
NestJS, Angular providers, constructor injection, inject(), forwardRef
React, Preact, Solid components and props across files, state hooks and effects
Vue, Svelte, Astro <script> and <script setup> blocks and frontmatter join the import graph under their own file names
Monorepos every tsconfig.json, references, path aliases; workspace packages are followed to their source by name, with or without node_modules; imports of own code that do not resolve are counted and reported

Every file is analysed under its nearest tsconfig.json or jsconfig.json, so each app of a monorepo resolves its own path aliases; an alias missing there is taken from another tsconfig that lists the file or sits above it. Vue, Svelte and Astro components are matched to the tsconfig that includes them. Code outside every tsconfig (a package without one, plain JavaScript beside TypeScript) is read as well, and a file a project imports is always analysed.

Old knots stay, new knots do not

unknot init writes .unknot.allow: the structural debt the project has today. From then on the run fails only on new findings. Fixing an old entry never fails anything, and a cycle that got smaller still counts as known.

npx unknot --update-allow   # record the current state again
npx unknot --adopt          # after an upgrade: bring the baseline up to date
npx unknot --all            # show the known debt too

A baseline written by an older unknot is brought up to date once with unknot --adopt (the Stop hook does it by itself); from then on only new findings stop a turn. Until then the text output labels findings missing from the outdated baseline not-in-baseline[...]. With an up-to-date baseline, findings of rules added later are labelled new-rule[...], and --adopt records them as debt.

Agents

Claude Code

Install the plugin once and every git repository is guarded:

/plugin install unknot --marketplace PatternVoid/unknot

On older versions of Claude Code: /plugin marketplace add PatternVoid/unknot, then /plugin install unknot@patternvoid.

The plugin adds What it does
Stop hook Runs unknot when the working tree has uncommitted source changes or a commit from the last three hours touched source files. When the turn ties a new knot, it hands the turn back to Claude with the report.
/unknot:untie The skill Claude follows to fix a finding from first principles: which layer is lower, what the outsider wants from the class, who owns the value.
/unknot:check Runs the report, with --all for the known debt.
/unknot:score Grades the codebase from A to F and names what drives the grade.

The hook works in every git repository. It scans when the working tree has uncommitted source changes or a commit from the last three hours touched source files, checks the nearest folder with a .unknot.allow or .unknot.json (the repository root otherwise), and skips a tree it has already passed. On the first run in a project it records today's knots in .unknot.allow, so only new ones stop a turn.

To guard a single repository for the whole team instead, commit the hook with it: npx unknot init adds it to .claude/settings.json.

{
  "hooks": {
    "Stop": [{ "hooks": [{ "type": "command", "command": "npx unknot hook", "timeout": 180 }] }]
  }
}

Codex, Cursor and every other agent

npx unknot init writes these rules into CLAUDE.md when the project has one, otherwise into AGENTS.md:

## Structure

Run `npx unknot` before finishing a task.
A finding is fixed from first principles, not by moving code around to hide it:
which module is the lower layer, why does anyone outside need this field,
what single call would the caller want. Fix the leaks of one class together.
Never add entries to `.unknot.allow`.

CI

- run: npx unknot --format github

--format github annotates the pull request diff. --format sarif feeds GitHub code scanning, --format json feeds everything else.

Exit code Meaning
0 no new findings
1 new findings, or an outdated baseline with findings not recorded in it
2 usage or setup error

How to untie a knot

Knot The fix
Cycle Read the layer order in the finding. Move the piece both sides share into the lower layer, or invert the call. Remove the named upward imports and the whole cycle is gone.
Tangle One owner calls both classes; the other side receives a callback or an event and stops knowing its partner.
Field leak Ask what the outsider is trying to do and give the class a method that says it: pause() instead of paused = true.
Shallow module Call the target directly, or give the wrapper real work.
Prop drilling Let the owner of the value render the consumer as children, or let the consumer read a context or store.
Wide injection Group collaborators by the job they serve and split the class along those jobs.

Configuration

None is needed. Everything below is optional.

Command line options
unknot [dir] [options]

Architecture linter for TypeScript and JavaScript: deep modules, narrow interfaces.
Findings listed in .unknot.allow are known debt and do not fail the run.

  --update-allow     write every current finding into .unknot.allow
  --adopt            record findings the baseline does not know yet (new rules, older unknot), keep the rest
  --all              show known debt too
  --score            grade the whole project from A to F, known debt included
  --badge            print a README badge with the grade
  --rule <id>        only these rules (repeat or separate with commas)
  --format <name>    text | json | sarif | github
  --json             same as --format json
  --list-rules       print every rule
  --explain <id>     what a rule means and how to fix it
  --version, --help

unknot init [dir] record today's debt, add the Claude Code Stop hook and the rules for agents
unknot hook       Claude Code Stop hook: check the project the agent worked in

Exit code: 0 clean, 1 new findings or a baseline that needs --adopt, 2 usage or setup error.
.unknot.json
{
  "projects": ["backend", "frontend/tsconfig.app.json"],
  "ignore": ["scripts/**", "src/generated/**"],
  "rules": {
    "long-file": { "max": 1000 },
    "wide-directory": { "max": 25 },
    "wide-injection": { "max": 7 },
    "prop-drilling": { "minComponents": 2 },
    "shallow-module": { "minForwards": 3 },
    "field-leak": { "minUsers": 2 },
    "shared-state": { "minWriters": 3 },
    "wide-component": { "max": 12 },
    "duplicate-type": { "minMembers": 6 },
    "forward-ref": false
  }
}

A projects entry is a tsconfig file or a directory that contains one; the listed projects are the whole scan, together with the files they import. Defaults: long-file.max 1500, wide-directory.max 40, wide-injection.max 9, wide-component.max 15, prop-drilling.minComponents 3, shallow-module.minForwards 3, field-leak.minUsers 1, shared-state.minWriters 2, duplicate-type.minMembers 4.

Skipped on their own:

  • Tests: files with a test suffix (.test., .spec., .e2e., .e2e-spec., .eval., .bench., .stories., .cy., .vitest., .test-d., .spec-d., .mock., .mocks., .fixture., .fixtures., .test-*.), names that end in _spec or _test, stories.* files, and folders named test, tests, testing, __tests__, __mocks__, __snapshots__, __fixtures__, mocks, fixtures and e2e.
  • Test support: test-utils, test-helpers, test-support, test-harness, test-fixtures, test-setup, test-kit and test-mocks, as a file or a folder.
  • Generated files: a header comment that says the file is generated (@generated, auto-generated, This file is generated, Generated by …, DO NOT EDIT, Vendored from …), the names *.generated.*, *.gen.*, *.pb.*, *_pb.*, database.types.ts and gql/graphql.ts, and the folders generated, __generated__, auto-generated, autogenerated and auto_generated.
  • Vendored code (vendored, third_party, third-party) and agent folders (.claude, .cursor, .codex, .agents).
  • examples, example, demos, demo, samples, showcase, benchmarks, benchmark, cypress and playwright folders that sit beside the product source, and top-level folders whose names end in -examples, -demos or -samples (singular and _ forms too).
  • Committed build output: when the package manifest has a source field pointing into src/, the folder its main, module or types point to, such as lib/ of a React Native library.
  • .d.ts, .json, node_modules, minified files, and JavaScript in build output and vendor folders (dist, build, out, coverage, vendor, .next, .nuxt, .output, .svelte-kit, .astro, .turbo), and JavaScript under public/ and static/ outside any tsconfig.

An unknown rule, option or key in .unknot.json is an error, not a silent no-op.

Contributing

npm install
npm run check   # types, tests, and unknot on itself
npm run build

New rules and framework support are welcome: see CONTRIBUTING.md. Security reports: SECURITY.md.

License

MIT

Explore related projects

Loading…