Skip to content
Latchkey

husky / prepare Script Fails in CI - Fix Git Hook Install in CI

husky installs Git hooks from a prepare script that runs after npm install. In CI it can fail when there is no .git directory or husky is missing from the install.

What this error means

npm install fails on the prepare lifecycle script with husky: command not found or a husky install error, often in a Docker build or a shallow checkout with no .git directory.

npm
> my-app@1.0.0 prepare
> husky install

sh: 1: husky: command not found
npm ERR! code 127

Common causes

husky runs where there is no .git

In a Docker build or an export with no .git directory, husky install has no repo to attach hooks to and errors.

husky is not installed when prepare runs

With --production or --ignore-scripts off, husky may be absent or the prepare order is wrong, so the binary is missing.

How to fix it

Make prepare a no-op outside a Git repo

  1. Guard the prepare script so it skips when there is no .git or in CI.
  2. Keep hooks working for local developers.
package.json
"prepare": "husky install || true"

Skip hook install in CI explicitly

  1. Set HUSKY=0 in CI to disable hook installation.
  2. Or run install with --ignore-scripts where hooks are not needed.
Workflow
env:
  HUSKY: 0

How to prevent it

  • Guard the prepare script for environments without .git, set HUSKY=0 in CI and Docker builds, and ensure husky is installed before prepare runs so installs never break on hooks.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →