Skip to content

Adopt Ashlar in an existing repository

At the end of this guide, ashlar check runs in CI and fails only when a file gets worse than it is today.

The examples come from a small repository: a Tauri desktop app in apps/desktop, an API in apps/api, and a package in packages/money. The outputs are what Ashlar printed there.

  1. Install Ashlar as a dev dependency. Ashlar is not on npm: each release attaches its packed tarball, kurvball-ashlar-<version>.tgz, and you install it by its address:

    Terminal window
    pnpm add -D https://github.com/kurvball/ashlar/releases/download/v1.2.0/kurvball-ashlar-1.2.0.tgz

    With npm, npm install -D and the same address. Your lockfile records the address and the tarball's checksum, so CI installs the same file with no token and nothing kept in your repository. To upgrade, install the newer release's address.

    To run a change that isn't released yet, build the tarball from Ashlar's repository instead (git clone https://github.com/kurvball/ashlar.git, then pnpm install and pnpm pack there), copy it into your repository, for example as vendor/kurvball-ashlar-<version>.tgz, commit it, and install it from there: pnpm add -D ./vendor/kurvball-ashlar-<version>.tgz. Installing from ../ashlar/ instead would leave a path in your lockfile that CI doesn't have.

    Ashlar needs Node 22.18 or later, and Git. Run it with pnpm exec ashlar, yarn ashlar or npx --no-install ashlar. Never run a bare npx ashlar: a package named ashlar on npm is someone else's, and npx would download and run it. Check which version you have:

    Terminal window
    $ pnpm exec ashlar --version
    1.2.0
  2. Write ashlar.config.ts at the root. no-comment, no-disable and max-lines hold in every file under include; every other rule needs to know where an app's parts are, so it applies only inside an app named in apps. Name one app for each app in the repository:

    import { defineConfig } from '@kurvball/ashlar';
    export default defineConfig({
    include: ['apps', 'packages'],
    apps: [
    { root: 'apps/desktop', stack: 'tauri' },
    { root: 'apps/api', stack: 'web', main: ['src'], renderer: [], shared: [], areas: ['src/*'] },
    ],
    });

    include names the folders Ashlar checks. Each app names its stack, electron, tauri or web, and the stack says where its sides live: for Tauri, the screens in src/, the host in src-tauri/, features in src/features/*. The API has no screens, so it has no renderer, and each folder in its src/ is an area. Config lists every key and its default.

    A library or a CLI has no screens either: give it one web app whose main side is its source folder, with no renderer, and make each folder of it an area:

    export default defineConfig({
    include: ['src'],
    apps: [{ root: 'src', stack: 'web', main: ['.'], renderer: [], areas: ['*'] }],
    });

    areas matters here. A stack's default areas sit in its usual main folder (server/* for web), which a repository whose main side is its root doesn't have, and an app with no area has nothing for public-api-only to count. Ashlar says so rather than count zero:

    Terminal window
    $ pnpm exec ashlar check
    Ashlar checked 3 files in 0.1 s: no count rose.
    There is no baseline, so every count must stay at zero.
    Warning: apps[0] (src): none of its 3 main-side files is in a service area, so public-api-only counts nothing there. Its areas, `src/server/*`, match none of them. Name them in `areas`, such as `areas: ['*']` for each folder of the app's root, or give `areas: []` to say it has none.

    With areas: ['*'], the same files show what the warning hid:

    Terminal window
    $ pnpm exec ashlar check
    Ashlar checked 3 files in 0.1 s: 2 counts rose.
    public-api-only in src/cli.ts: 1, up from 0
    src/cli.ts:1:21
    Import another feature or area through its `index.ts`. If you need something inside it, it belongs in its index or in `shared/`.
    public-api-only in src/run/run.ts: 1, up from 0
    src/run/run.ts:1:22
    Import another feature or area through its `index.ts`. If you need something inside it, it belongs in its index or in `shared/`.

    A web client that calls its server with fetch: name fetch as the app's bridge, and client-only counts every fetch outside client/, as it counts Electron's or Tauri's packages. Without it, Ashlar doesn't know fetch reaches the other side:

    { root: 'apps/web', stack: 'web', bridge: { global: 'fetch' } }
  3. Run the check once, to see what is there:

    Terminal window
    $ pnpm exec ashlar check
    Ashlar checked 9 files in 0.2 s: 6 counts rose.
    no-comment in apps/api/src/orders/index.ts: 1, up from 0
    apps/api/src/orders/index.ts:3:1
    Comments go stale and nothing checks them. Rename it, or write a test. Git leads from any line to the item or task that wrote it.
    no-effect in apps/desktop/src/features/cart/Cart.tsx: 1, up from 0
    apps/desktop/src/features/cart/Cart.tsx:6:3
    `useEffect` belongs to `client/` and `primitives/`. A feature that needs one needs a hook in `primitives/`, named for what it does, instead.
    no-timer in apps/desktop/src/features/cart/Cart.tsx: 1, up from 0
    apps/desktop/src/features/cart/Cart.tsx:8:19
    A timer patches over a render you don't control. Use a hook from `primitives/`, named for what it waits on.
    feature-reach in apps/desktop/src/features/cart/reach.ts: 1, up from 0
    apps/desktop/src/features/cart/reach.ts:1:1
    Every feature folder holds a reach script, `reach.ts`: the developer's way to the feature as drive steps, ending on a snapshot of what it reaches. It is plain data that imports only types. Write one, then run it with `ashlar drive <feature>`.
    feature-reach in apps/desktop/src/features/search/reach.ts: 1, up from 0
    apps/desktop/src/features/search/reach.ts:1:1
    Every feature folder holds a reach script, `reach.ts`: the developer's way to the feature as drive steps, ending on a snapshot of what it reaches. It is plain data that imports only types. Write one, then run it with `ashlar drive <feature>`.
    no-comment in packages/money/src/total.ts: 1, up from 0
    packages/money/src/total.ts:1:1
    Comments go stale and nothing checks them. Rename it, or write a test. Git leads from any line to the item or task that wrote it.

    It exits with 1. With no baseline, every count must stay at zero, and an existing repository has breaks. If a break is in the wrong place, the layout is wrong: fix the app's folders in the config and run it again.

    Two words: a count is one rule's number in one file, and breaks are what it counts. "6 counts rose" means six pairs of a file and a rule went up; the baseline below holds 6 breaks in all. Most rules count each place they fire, so a file with three comments holds 3 no-comment breaks; max-lines counts the lines a file has over the limit, so a file of 724 lines holds 124.

  4. Take the baseline:

    Terminal window
    $ pnpm exec ashlar check --shrink
    Ashlar checked 9 files in 0.2 s and took the baseline: 6 breaks in ashlar.baseline.json.

    The baseline holds each file's count for each rule:

    {
    "feature-reach": {
    "apps/desktop/src/features/cart/reach.ts": 1,
    "apps/desktop/src/features/search/reach.ts": 1
    },
    "no-comment": {
    "apps/api/src/orders/index.ts": 1,
    "packages/money/src/total.ts": 1
    },
    "no-effect": {
    "apps/desktop/src/features/cart/Cart.tsx": 1
    },
    "no-timer": {
    "apps/desktop/src/features/cart/Cart.tsx": 1
    }
    }

    Commit ashlar.baseline.json. From now on, check passes while no file's count rises above it:

    Terminal window
    $ pnpm exec ashlar check
    Ashlar checked 9 files in 0.1 s: no count rose.
  5. Run the check in CI. Give it a script in package.json:

    {
    "scripts": {
    "check": "ashlar check"
    }
    }

    Then run pnpm check in your CI job. On GitHub Actions:

    steps:
    - uses: actions/checkout@v4
    with:
    fetch-depth: 0
    - uses: pnpm/action-setup@v4
    - uses: actions/setup-node@v4
    with:
    node-version: 22
    cache: pnpm
    - run: pnpm install --frozen-lockfile
    - run: pnpm check

    Ashlar compares with your main branch to tell which lines a change wrote: of main, origin/main, master and origin/master, it takes the one whose merge base with HEAD is closest. A pull request's checkout has no local main, so it uses origin/main, which fetch-depth: 0 fetches. A comment on a written line fails even when another comment in the file went, so the count stayed the same. Editing a line that holds a comment writes it too: fixing a path inside an old comment counts as a new comment. A comment can't be kept current, only replaced by a name or a test.

    Terminal window
    $ pnpm check
    Ashlar checked 12 files in 0.2 s: 1 count rose.
    no-comment in apps/api/src/sales/index.ts: 1 new one on lines changed since main. None may be added, even where others went.
    apps/api/src/sales/index.ts:4:3
    Comments go stale and nothing checks them. Rename it, or write a test. Git leads from any line to the item or task that wrote it.

    A change that adds a break fails the same way, with the message the agent reads:

    Terminal window
    $ pnpm check
    Ashlar checked 9 files in 0.2 s: 1 count rose.
    no-comment in apps/api/src/db/index.ts: 1, up from 0
    apps/api/src/db/index.ts:2:3
    Comments go stale and nothing checks them. Rename it, or write a test. Git leads from any line to the item or task that wrote it.
  6. Lower the baseline as breaks go. When a fix takes a count down, as a reach script for the cart feature does here, check says so:

    Terminal window
    $ pnpm check
    Ashlar checked 10 files in 0.2 s: no count rose.
    1 break in the baseline is gone: `ashlar check --shrink` lowers it.
    Terminal window
    $ pnpm check --shrink
    Ashlar checked 10 files in 0.2 s: no count rose.
    The baseline now holds 5 breaks.

    --shrink only ever lowers a count. Commit the baseline with the fix.

    When the layout grows later, a wider include, a new app or new areas, new counts appear that --shrink won't take in. Take them in on purpose with ashlar check --accept-rise, which says what it took, or delete ashlar.baseline.json and take it again with --shrink.

  7. Turn a rule off, if it is wrong for the whole project. No comment in code can turn a rule off, so it goes in the config:

    import { defineConfig } from '@kurvball/ashlar';
    export default defineConfig({
    include: ['apps', 'packages'],
    apps: [
    { root: 'apps/desktop', stack: 'tauri' },
    { root: 'apps/api', stack: 'web', main: ['src'], renderer: [], shared: [], areas: ['src/*'] },
    ],
    rules: { 'no-timer': 'off' },
    });
    Terminal window
    $ pnpm check
    Ashlar checked 9 files in 0.2 s: no count rose.
    1 break in the baseline is gone: `ashlar check --shrink` lowers it.

    The rule's counts in the baseline are now gone, and pnpm check --shrink takes them out.

  8. Replace a rule's message with your own words, such as the name of your own hook:

    import { defineConfig } from '@kurvball/ashlar';
    export default defineConfig({
    include: ['apps', 'packages'],
    apps: [
    { root: 'apps/desktop', stack: 'tauri' },
    { root: 'apps/api', stack: 'web', main: ['src'], renderer: [], shared: [], areas: ['src/*'] },
    ],
    messages: {
    'no-timer':
    'A timer patches over a render you don’t control. Wait with `useDebounced` from `primitives/`.',
    },
    });
    Terminal window
    $ pnpm check
    Ashlar checked 9 files in 0.2 s: 1 count rose.
    no-timer in apps/desktop/src/features/search/Search.tsx: 1, up from 0
    apps/desktop/src/features/search/Search.tsx:4:36
    A timer patches over a render you don’t control. Wait with `useDebounced` from `primitives/`.

    The same words reach ashlar ledger, ashlar brief and the onboarding guide.

  9. Write the onboarding guide, and keep it current. ashlar onboard writes it into docs/onboarding/ (or where onboard.out says): what the system is, each area, its decisions and rules, and the questions only a person can answer. ashlar onboard --check fails when it is out of date, so run it with the check:

    {
    "scripts": {
    "check": "ashlar check && ashlar onboard --check"
    }
    }

    The guide is generated, so leave it as Ashlar writes it:

    • Keep formatters off it. Prettier would rewrite its Markdown, and --check would call it stale. Add the folder to .prettierignore:

      docs/onboarding/
    • Run ashlar onboard again after a change it describes, and commit the result. The guide lists your package.json scripts, your areas, DECISIONS.md and .claude/rules/, so changing a script makes --check fail until it is written again.

    Onboarding says what the guide holds.