Agent skill
typescript-husky-setup
Install, repair, and verify Husky + lint-staged pre-commit hooks in Node.js TypeScript repositories with staged-file-only checks and deterministic validation. Use when users ask to add Git hooks, fix broken pre-commit execution, standardize commit-time lint/format checks, or align cross-platform hook behavior.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/typescript-husky-setup
SKILL.md
TypeScript Husky Setup
Set up fast, staged-file-only pre-commit quality checks using Husky and lint-staged.
Scope and outcomes
- Install or repair Husky and lint-staged.
- Ensure pre-commit runs only staged file checks.
- Preserve existing scripts and repository conventions.
- Verify the hook path actually executes during
git commit.
Preconditions
- Repository contains
package.jsonand is intended for Node.js tooling. - Git repository is initialized (
.gitexists). - Formatter/linter commands used by lint-staged exist (direct binaries or package scripts).
- Use the repository's existing package manager when detectable; otherwise default to
npm.
Step 1: Baseline detection
- Read
package.jsonand detect package manager from lockfiles. - Check whether Husky is already initialized (
.husky/folder and hook files). - Check whether
lint-stagedconfig exists (package.jsonkey or dedicated config file). - Identify project file types in scope (
ts,tsx, optionallyjs,json,md) before editing globs.
Step 2: Install and initialize safely
Run from repository root.
npm install --save-dev husky lint-staged
npx husky init
Required package.json behavior:
- Ensure a
preparescript exists and runs Husky. - If
preparealready exists, merge behavior without deleting existing commands.
Step 3: Configure lint-staged deterministically
Add or repair lint-staged rules so they target staged files only.
Baseline example:
"lint-staged": {
"*.{ts,tsx}": [
"prettier --write",
"eslint --fix"
]
}
Rules:
- Match actual repository file types; do not invent unsupported commands.
- Prefer existing project scripts when direct commands are unavailable.
- Keep commands fast; avoid full-project checks in pre-commit.
Step 4: Configure pre-commit hook
Set .husky/pre-commit to execute lint-staged.
npx lint-staged
Only add tests in pre-commit when explicitly requested, and keep them fast (non-coverage). Additional guidance is in reference.md.
Step 5: Verification gate (required)
- Stage a deliberately misformatted file matched by lint-staged.
- Run
git commit -m "test hooks". - Confirm the pre-commit hook executes and only staged files are processed.
- If files were auto-fixed, re-stage and re-run commit.
- Confirm commit succeeds after fixes with no unrelated file processing.
Repair matrix
- Hook not executing: run
npm run prepare, then verify.husky/pre-commitexists. lint-stagedreports no files: adjust glob patterns to actual staged paths.- Permission issues on hook files: re-run
npx husky initand ensure hook file is executable. - Command not found inside hook: use local binaries via package scripts or install missing tool.
- Monorepo mismatch: run from repo root and scope globs/commands to affected packages.
Non-goals
- Do not add heavy CI gates (coverage/e2e) to pre-commit by default.
- Do not rewrite unrelated npm scripts or lint configs.
- Do not enforce a package manager switch.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?