logo hsb.horse
← Back to blog index

Blog

Lefthook Setup Procedure: Run Biome Automatically in pre-commit and pre-push

A practical Lefthook setup procedure to run Biome formatting and linting automatically at commit and push time. Covers the full flow from ADR documentation to configuration, installation, and verification.

Published: Updated:

You forget formatting before commit, then lint blocks you right before push. If this repeats, you lose time before review even starts.

Automate formatting and static checks with Git Hooks to reduce manual misses. In this setup, lefthook runs Biome at commit and push time.

Goal

Automatically run Biome formatting and linting at commit and push time.

Prerequisites

  • bun is available
  • Work from the repository root

Setup Steps

  1. Create an ADR in Japanese and document the policy
  2. Create this procedure memo under ailog/
  3. Add lefthook as a development dependency
  4. Create lefthook.yml and configure formatting/linting for pre-commit and pre-push
  5. Add the prepare script (lefthook install) to package.json
  6. Run bun run prepare to install Git Hooks
  7. Verify with lefthook run pre-commit and lefthook run pre-push
  8. If there are issues, fix the configuration
  9. After setup, create a draft blog post under ailog/
  10. Translate the ADR into other languages (en / de / fr / ko)

Verification Checklist

  • lefthook.yml exists and defines pre-commit / pre-push
  • bun run prepare succeeds
  • lefthook run pre-commit succeeds
  • lefthook run pre-push succeeds

Execution Notes

pre-commit targets staged files and runs biome format --write {staged_files} and biome check --write {staged_files}.

pre-push also targets staged files and runs biome format --write {staged_files} and biome check --write {staged_files}.

Keeping Git Hook settings in the repository makes operations consistent across environments. If you want fewer review-noise diffs, locking this down early is the fastest route.