| title | Adopt Fallow in an existing repo | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| description | Bring an existing TypeScript or JavaScript codebase to a clean Fallow policy, then keep new changes clean with fallow audit. Drive the cleanup with an AI agent. | ||||||||||
| keywords |
|
||||||||||
| icon | rocket |
This guide is for repositories that already have backlog: unused code, duplicates, complexity hotspots, and existing exceptions.
By the end of this guide you will have:
- a repo-level Fallow policy encoded in config
- dead code fixed or intentionally modeled
- duplication at or below your chosen threshold
- complex functions refactored or consciously widened with a written justification
fallow auditenforcing the same policy on changed files
These are different goals. Both matter. Do them in order.
Full-repo analysis to understand and clean the whole codebase. Use `fallow`, `fallow dead-code`, `fallow dupes`, and `fallow health`. Changed-files gate that enforces the policy on every PR. Use `fallow audit` after the repo is clean.Start with repo clean. Then turn on PR clean.
Run `fallow migrate` first to port your knip config, then follow this guide. Apply this flow per workspace package. Use `fallow --workspace ` and a shared root config.From your project root:
npx fallowThen the focused commands you will use during cleanup:
npx fallow dead-code # Cleanup candidates
npx fallow dupes # Repeated logic
npx fallow health # Complexity and refactor targetsIf you do not yet have a config file:
fallow initfallow init auto-detects your project structure (package manager, workspaces, frameworks) and generates a tailored starting config. It also adds .fallow/ to your .gitignore.
Do not start by suppressing findings one by one. That path turns into an ever-growing list of inline exceptions and no coherent policy.
Not the policy owner? Run section 3 first on a branch, then bring the findings into the policy discussion. Fallow output is a good forcing function for the "what do we actually care about" conversation.First decide, as a team:
- what counts as a real entry point (workers, scripts, route files, dynamically loaded modules)
- which files are generated or out of scope
- which packages are public APIs that ship exports outside the repo
- which dependencies are runtime-provided or intentionally retained
- which health thresholds you actually want to enforce
- whether duplication should warn or fail
A reasonable starting point:
Rules you do not list inherit their defaults. Health thresholds default to maxCyclomatic: 20 and maxCognitive: 15; override in a health block only when your repo's realistic baseline differs.
Use this order for most existing repos. Each step removes noise that would otherwise distort the next step.
High confidence, low debate. These are real bugs waiting to happen and should be cleared first.```bash
npx fallow dead-code --unresolved-imports
npx fallow dead-code --unlisted-deps
```
```bash
npx fallow dead-code --unused-files
npx fallow list --entry-points
```
```bash
npx fallow dead-code --unused-deps
```
```bash
npx fallow dead-code --unused-exports --unused-types
```
Add `--unused-enum-members` and `--unused-class-members` when you want to focus on those categories explicitly. See the [`fallow dead-code` reference](/cli/dead-code) for every filter flag.
```bash
npx fallow dupes
npx fallow dupes --mode semantic # also catch renamed-variable clones
```
```bash
npx fallow health
```
Do not default to inline suppression. Pick the mechanism that matches the reason.
Exports consumed outside the repo (published libraries, SDKs, public packages).
Prefer, in order:
@public,@internal,@beta,@alphaJSDoc visibility tags on the exportpublicPackagesas the coarse switch for "this whole package is external API"ignoreExportsonly when file-level or export-level exceptions cannot be expressed any other way
publicPackages and visibility tags are complementary, not alternatives: publicPackages marks the package as externally consumed; @public/@internal tags distinguish public API from internal helpers that happen to be exported for cross-file use.
Files your framework or runtime invokes but no other module imports directly (workers, CLI scripts, route files, plugin modules).
Prefer, in order:
- built-in plugin detection (Next.js, Vite, NestJS, Remotion, and dozens more are handled out of the box)
entryfor project-specific entry globsdynamicallyLoadedfor code pulled in through reflection, manifests, or dynamic importsfallow list --entry-pointsto inspect what Fallow already considers reachable
Files produced by a build step, code generator, or vendored third-party bundle.
Prefer:
ignorePatternsto exclude them from analysis entirelyhealth.ignorewhen the noise is health-only and dead-code analysis should still run- duplication configuration for clone-heavy generated code
Packages installed for runtime usage only (no static import), CLI tools, or peer dependencies.
Prefer:
ignoreDependencieswith the exact package names
An export you want to keep around deliberately (compatibility shims, future API).
Prefer:
/** @expected-unused */on the export
A specific site where Fallow is wrong and no config rule captures the reason cleanly.
Prefer:
// fallow-ignore-next-line <issue>on the line above// fallow-ignore-file <issue>only when the whole file is truly exceptional
The project genuinely has a different standard for a whole category.
Prefer:
rules,health, duplication thresholds, oroverridesblocks
Do this only when it reflects a real team policy, not to hide a few ugly hotspots.
See [suppression](/configuration/suppression) for the full decision tree and examples, and [configuration overview](/configuration/overview) for every key.Narrow exceptions are an asset. Broad exceptions are a debt.
Good:
- a single
@publicexport on a library entry point - one
ignoreDependenciesentry for a runtime-provided package - one
entrypattern for worker scripts - one file-level generated-code ignore with a comment explaining why
Bad:
- broad
ignorePatternsthat silently exclude half the repo - repeated inline suppressions that could be one config rule
- raising global
health.maxCyclomaticto hide a handful of hotspots (acceptable only when the new threshold reflects a thought-through project standard with written justification)
If you cannot explain an exception in one sentence, it is probably the wrong mechanism.
Work in two stages. Most teams ship fallow audit at the end of stage 1 and finish stage 2 over the following weeks.
- the chosen policy is encoded in config, not accumulated in scattered suppressions
- unresolved imports and unlisted dependencies are cleared
- blatant dead code (unused files, unused dependencies) is removed
fallow auditis wired into CI and passes for new changes against the default branch
- no functions above your chosen health thresholds, either by refactoring or by consciously widening the threshold with written justification
- duplication at or below the chosen threshold
- stale suppressions gone or consciously accepted
Once stage 1 is done, add the PR gate:
npx fallow auditfallow audit runs dead code, duplication, and complexity analysis scoped to changed files, then returns a pass, warn, or fail verdict. See the fallow audit reference for flags and CI recipes.
```jsonc
{
"rules": {
"unused-exports": "warn",
"unused-files": "warn",
"unused-dependencies": "warn"
}
}
```
Risk: warn-only gates become warning-forever gates. Set a calendar reminder to promote rules to `error` after the first clean month.
```bash
# Save baselines once on the default branch
fallow dead-code --save-baseline fallow-baselines/dead-code.json
fallow health --save-baseline fallow-baselines/health.json
fallow dupes --save-baseline fallow-baselines/dupes.json
# Audit only new issues on PRs
fallow audit \
--dead-code-baseline fallow-baselines/dead-code.json \
--health-baseline fallow-baselines/health.json \
--dupes-baseline fallow-baselines/dupes.json
```
Store committed baselines outside `.fallow/` (which `fallow init` adds to `.gitignore` for machine-local cache). `fallow-baselines/` is the recommended default. Commit the baseline files so every PR compares against the same snapshot, and regenerate on a schedule (quarterly, or per release) rather than per merge, otherwise teams silently absorb new debt every time CI runs.
Pair this with Option A or B, not instead of them. This is a local reinforcement layer. Keep CI on `fallow audit` so human pushes and non-Claude workflows are still covered.
Runtime errors (no base ref yet, first commit in an empty repo, config errors) fail open so new repos do not get stuck.
See [Claude Code hooks](/integrations/claude-hooks) for the full recipe, or generate the files with:
```bash
fallow hooks install --target agent
```
You can also configure baselines in .fallowrc.json and run fallow audit with no flags:
{
"audit": {
"deadCodeBaseline": "fallow-baselines/dead-code.json",
"healthBaseline": "fallow-baselines/health.json",
"dupesBaseline": "fallow-baselines/dupes.json"
}
}Fallow finds the problems. An AI agent (Claude Code, Cursor, Codex, Windsurf, any shell-capable coding assistant) is the right tool to fix them: edits are mechanical but decisions ("delete this export" vs. "mark it @public" vs. "add it to entry") benefit from code-aware judgement.
Three levels of integration, pick whichever your agent supports:
Install `fallow-skills` for Claude Code, Cursor, Windsurf, or any Agent Skills compatible agent. Once installed, the skill works offline; the agent does not need to fetch docs URLs during use. Structured tool calling with JSON output and `_meta` explanations. Works alongside skills. Any agent that can run a shell command can drive Fallow. Use the copy-paste prompt below. Paste this prompt into your agent. It is self-contained: the agent does not need to fetch this page to follow it.Adopt Fallow in this repository.
Goal:
- use full-repo analysis first (`fallow`, `fallow dead-code`, `fallow dupes`, `fallow health`), not `fallow audit`
- fix real dead code, duplication, and complexity issues in code
- model intentional exceptions with the narrowest correct mechanism
- end with no functions above the repo's chosen health thresholds, or a consciously widened threshold with written justification
- then set up `fallow audit` as a PR gate
Process:
1. Run `npx fallow`, then `npx fallow dead-code`, `npx fallow dupes`, and `npx fallow health`. Use `--format json` if you want structured output.
2. If no config exists, run `fallow init` and create a minimal repo policy.
3. Fix high-confidence issues first:
- unresolved imports
- unlisted dependencies
- unused files (sanity-check with `fallow list --entry-points`)
- unused dependencies
4. For each remaining finding, choose one path:
- fix it in code (preferred)
- model it in config
- add a narrow inline exception only if it is truly one-off
5. Match reasons to mechanisms:
- external API: `@public` / `@internal` / `@beta` / `@alpha`, or `publicPackages`
- runtime or framework entry point: `entry`, `dynamicallyLoaded`, plugin-aware config
- generated code: `ignorePatterns`, `health.ignore`
- intentionally retained dependency: `ignoreDependencies`
- intentional unused export: `@expected-unused` (preferred over inline comments because it self-cleans)
- one-off false positive: `fallow-ignore-next-line`
- repo-wide policy: `rules`, `health`, duplication settings, `overrides`
6. Prefer config-level modeling over repeated suppression.
7. Keep every exception narrow and explain why it exists in a commit message.
8. Re-run Fallow after each batch until the repo is clean under the chosen policy.
9. Only after repo cleanup, run `npx fallow audit` and wire it into CI.
At the end, report:
- code changes
- config changes
- exceptions added and why
- anything left
- the final commands and outputs that show the repo is clean
{ "$schema": "https://raw.githubusercontent.com/fallow-rs/fallow/main/schema.json", "ignorePatterns": ["**/*.generated.ts", "**/*.d.ts"], "rules": { "unresolved-imports": "error", "unlisted-dependencies": "error", "unused-exports": "warn" } }