Check Markdown before every commit

Copy-paste hooks for pre-commit, lint-staged, husky, and lefthook that check the Markdown a commit stages.

The airlock does not argue. It checks the seal before the door opens, not after.

Prompt for your coding agentOpen in Claude ↗

Add mediva to this repo (npm i -D mediva) and a pre-commit hook that runs npx --no-install mdv check --staged, so staged Markdown is checked against its contracts before every commit.

npx --no-install mdv check --staged
FlagWhy it suits a hook
--stagedchecks the staged documents, read from the git index, so unstaged edits never leak in
explicit files with no contractthe lint gate only, plus a no-contract warning; fail only on lint

pre-commit

.pre-commit-config.yaml
repos:
  - repo: https://github.com/jamespacileo/mediva-public
    rev: main # pin a release tag; `pre-commit autoupdate` does it for you
    hooks:
      - id: mdv

Or, with the mdv already in your devDependencies:

.pre-commit-config.yaml
repos:
  - repo: local
    hooks:
      - id: mdv
        name: mdv check
        entry: npx --no-install mdv check
        language: system
        files: \.md$

lint-staged

package.json
{
  "lint-staged": {
    "*.md": "mdv check"
  }
}

husky

.husky/pre-commit
npx --no-install mdv check --staged

lefthook

lefthook.yml
pre-commit:
  commands:
    mdv:
      run: npx --no-install mdv check --staged

Variations

WantDo
a quieter rulerules: { "too-few-words": "warn" } (What blocks)
the whole branch, not one commitmdv check --new

On this page