$ show typicode/husky
Husky is a zero-dependency CLI tool that enables Git hooks using the native core.hooksPath feature introduced in Git 2.9. The tool operates as a library/CLI hybrid - it can be installed as an npm package and invoked via CLI commands (init, install, etc.) or imported programmatically. The architecture is intentionally minimal: bin.js handles CLI entry points, index.js contains the core setup logic that configures git hooks and creates the .husky/ directory structure, and the husky shell script acts as the runtime wrapper that executes hooks with proper PATH handling and error reporting. The tool modifies git configuration (core.hooksPath) to point to .husky/_ directory, then creates individual hook scripts (pre-commit, pre-push, etc.) that delegate to the main husky runner. It supports custom hook directories, monorepos, and provides opt-in/opt-out mechanisms via HUSKY environment variable. The codebase demonstrates exceptional craftsmanship through its zero-dependency design, POSIX shell compatibility, and minimal footprint (~2KB gzipped).
The LLM identified 3 files worth highlighting for reuse:
Core setup logic that configures Git hooks using core.hooksPath. The function is self-contained, handles edge cases (missing .git, HUSKY=0, path traversal), and creates the complete hook infrastructure in one call. Demonstrates skill in cross-platform compatibility and defensive programming. Can be extracted as a standalone Git hooks setup utility.
The runtime shell script that executes hooks. Handles PATH manipulation (node_modules/.bin), sources user init scripts, manages exit codes, and provides user-friendly error messages. Demonstrates POSIX shell best practices and robust error handling. Highly reusable pattern for shell-based tooling that needs environment setup.
CLI entry point that handles init command (modifies package.json prepare script) and deprecated command warnings. Shows clean command routing and backward compatibility handling. The init logic that adds prepare script to package.json is a reusable pattern for npm package setup automation.