Skip to main content
In a typical JS project, running a linter before commit requires:
  • husky
  • lint-staged
  • @commitlint/cli
  • @commitlint/config-conventional
  • A .husky directory
  • A prepare script
  • A lint-staged config
wit has hooks built in. One config file.
That’s it.

Why wit Hooks Replace Husky

Quick Start

Configuration File

wit uses .wit/hooks.json for hook configuration:

Config Locations

wit looks for config in these locations (in order):
  1. .wit/hooks.json (recommended)
  2. wit.config.json
  3. package.json under "wit" key

Available Hooks

Commands

Setup Hooks

Add Hook Commands

Sync Configuration

List Hooks

Output:

Other Commands

Lint-Staged Style Configuration

The staged config runs commands only on staged files matching patterns:

Pattern Syntax

  • Uses JavaScript regex patterns
  • Files are passed as arguments to commands
  • Use {} placeholder to control file position:

Automatic Setup with npm

Add to your package.json:
This ensures all team members get the same hooks after npm install.

Hook Definition Formats

Simple String

Array of Commands

Full Definition Object

Writing Custom Hooks

Basic Structure

Hooks are shell scripts in .wit/hooks/:

Pre-commit Hook

Block commits that don’t meet criteria:

Commit Message Validation

Pre-push Hook

Run tests before pushing:

Bypassing Hooks

Use --no-verify to skip hooks:

Hook Environment

Hooks have access to these environment variables:

Migration from Husky

Before (Husky + lint-staged)

After (wit only)

Remove these packages:
  • husky
  • lint-staged
  • @commitlint/cli (use wit’s built-in validation)

Best Practices

Keep hooks fastLong-running hooks slow down your workflow. For expensive operations:
  • Run only on changed files (use staged config)
  • Use background jobs for non-blocking tasks
  • Consider CI for comprehensive checks
Version control your configCommit .wit/hooks.json to share hooks with your team:
Handle errors gracefullyAlways provide clear error messages:

Troubleshooting

  1. Check if hooks are synced: wit hooks
  2. Run sync: wit hooks sync
  3. Check permissions: ls -la .wit/hooks/
Run wit hooks sync after editing .wit/hooks.json
Use the --no-verify flag:
Ensure:
  1. .wit/hooks.json is committed
  2. postinstall script calls wit hooks sync
  3. Team members run npm install after pulling