
ln-742-precommit-setup
Configures Husky, lint-staged, commitlint, and Python pre-commit hooks. Use when adding Git hook automation to a project.
- Installs
- 385
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/levnikolaevich/claude-code-skills --skill ln-742-precommit-setup- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads ln-742-precommit-setup automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
Paths: File paths (
references/,../ln-*) are relative to this skill directory.
ln-742-precommit-setup
Type: L3 Worker Category: 7XX Project Bootstrap
Sets up Git hooks for automated code quality enforcement before commits.
Purpose & Scope
Does:
- Installs hook management tools (Husky or pre-commit)
- Configures staged file linting (lint-staged or pre-commit hooks)
- Sets up commit message validation (commitlint)
- Verifies hooks trigger correctly
Does NOT:
- Configure linters themselves (ln-741 does this)
- Set up test infrastructure (ln-743 does this)
- Modify source code
Supported Stacks
| Technology | Hook Manager | Staged Linting | Commit Validation |
|---|---|---|---|
| Node.js | Husky | lint-staged | commitlint |
| Python | pre-commit | pre-commit hooks | pre-commit hook |
| Mixed | Both (if needed) | Stack-specific | commitlint |
Phase 1: Check Existing Hooks
Before installing, check for existing hook configurations.
Files to Check:
| Tool | Indicators |
|---|---|
| Husky | .husky/ directory, husky in package.json |
| pre-commit | .pre-commit-config.yaml |
| lint-staged | lint-staged in package.json or .lintstagedrc* |
| commitlint | commitlint.config.*, .commitlintrc* |
Decision Logic:
- If hooks exist and working: SKIP (inform user)
- If partial setup: ASK user to complete or replace
- If no hooks: CREATE from templates
Phase 2: Install Hook Manager
Node.js Projects (Husky)
npm install -D husky
npx husky init
This creates:
.husky/directory.husky/pre-commithook file- Adds
preparescript to package.json
Python Projects (pre-commit)
pip install pre-commit
# OR with uv:
uv add --dev pre-commit
pre-commit install
This creates:
.git/hooks/pre-commit(managed by pre-commit)- Requires
.pre-commit-config.yamlfor configuration
Phase 3: Configure Staged Linting
Node.js (lint-staged)
npm install -D lint-staged
Create configuration (.lintstagedrc.mjs or in package.json):
Key Rules:
- TypeScript files: ESLint + Prettier
- JSON/MD/CSS: Prettier only
- C# files: dotnet format (if mixed project)
CRITICAL FIX: For .NET files, use correct syntax:
"*.cs": "dotnet format --include"is WRONG Use:"*.cs": "dotnet format whitespace --include"or run dotnet format separately
Python (pre-commit hooks)
Configuration in .pre-commit-config.yaml:
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.0
hooks:
- id: ruff
args: [--fix]
- id: ruff-format
Phase 4: Configure Commit Message Validation
Node.js (commitlint)
npm install -D @commitlint/cli @commitlint/config-conventional
Create commitlint.config.mjs with:
- Conventional Commits format
- Allowed types: feat, fix, docs, style, refactor, test, chore, ci
- Max header length: 100 characters
Update Husky hook
Add commit-msg hook:
echo 'npx --no -- commitlint --edit "$1"' > .husky/commit-msg
Python (pre-commit hook for commit message)
Add to .pre-commit-config.yaml:
- repo: https://github.com/compilerla/conventional-pre-commit
rev: v3.4.0
hooks:
- id: conventional-pre-commit
stages: [commit-msg]
Phase 5: Test Hooks
Verify hooks work correctly.
Test 1: Lint-staged triggers
# Create a file with lint issues
echo "const x=1" > test-file.ts
git add test-file.ts
git commit -m "test: verify hooks"
# Expected: lint-staged runs, either fixes or blocks
Test 2: Commit message validation
git commit --allow-empty -m "bad message"
# Expected: commitlint rejects
git commit --allow-empty -m "test: valid message format"
# Expected: commit succeeds
Cleanup:
rm test-file.ts
git reset HEAD~1 # If test commit was made
Critical Rules
RULE 1: Husky requires Git repository (
git initfirst).
RULE 2: lint-staged MUST have linters configured first (run ln-741 before ln-742).
RULE 3: Document
--no-verifyescape hatch for emergency commits.
RULE 4: pre-commit hooks should auto-fix when possible (
--fixflag).
Monitor (2.1.98+): When hook verification invokes lint/test commands expected >30s, use Monitor. Fallback: Bash(run_in_background=true).
Definition of Done
- Hook manager installed (Husky or pre-commit)
- Staged linting configured and working
- Commit message validation configured
- Test commit triggers hooks correctly
- User informed of:
- How hooks work
- How to skip hooks in emergency (
git commit --no-verify) - Commit message format required
Reference Files
| File | Purpose |
|---|---|
| husky_precommit_template.sh | Husky pre-commit hook |
| husky_commitmsg_template.sh | Husky commit-msg hook |
| lintstaged_template.mjs | lint-staged configuration |
| commitlint_template.mjs | commitlint configuration |
| precommit_config_template.yaml | Python pre-commit config |
| hooks_guide.md | Detailed hooks guide |
Error Handling
| Error | Cause | Resolution |
|---|---|---|
| Husky not running | Missing prepare script | Run npx husky init again |
| lint-staged fails | Missing linter | Run ln-741 first |
| pre-commit not found | Not in PATH | pip install pre-commit |
| Hooks not triggering | Git hooks disabled | Check .git/hooks/ permissions |
| Windows path issues | Shell script format | Use cross-platform syntax |
Emergency Bypass
Document for users:
# Skip all hooks (use sparingly!)
git commit --no-verify -m "emergency: bypass hooks"
# Skip only pre-commit (keeps commit-msg)
HUSKY=0 git commit -m "fix: urgent hotfix"
Version: 2.0.0 Last Updated: 2026-01-10
FAQ
What does the ln-742-precommit-setup skill do?
Configures Husky, lint-staged, commitlint, and Python pre-commit hooks. Use when adding Git hook automation to a project.
How do I install ln-742-precommit-setup?
Run npx skills add https://github.com/levnikolaevich/claude-code-skills --skill ln-742-precommit-setup in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/ln-742-precommit-setup/ (personal) or .claude/skills/ln-742-precommit-setup/ (project).
Which AI agents can use ln-742-precommit-setup?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is ln-742-precommit-setup safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains ln-742-precommit-setup?
It is published by levnikolaevich in levnikolaevich/claude-code-skills. It has 385 recorded installs.
More from levnikolaevich/claude-code-skills
ln-100-documents-pipeline
levnikolaevich/claude-code-skills
Creates complete project documentation system (project docs, reference, tasks, tests). Use when bootstrapping docs from scratch or regenerating all.
ln-620-codebase-auditor
levnikolaevich/claude-code-skills
Open the skill to read its SKILL.md instructions.
ln-775-api-docs-generator
levnikolaevich/claude-code-skills
Open the skill to read its SKILL.md instructions.
ln-624-code-quality-auditor
levnikolaevich/claude-code-skills
Open the skill to read its SKILL.md instructions.
ln-782-test-runner
levnikolaevich/claude-code-skills
Open the skill to read its SKILL.md instructions.
ln-634-test-coverage-auditor
levnikolaevich/claude-code-skills
Open the skill to read its SKILL.md instructions.
Popular code quality & workflow skills
grill-me
mattpocock/skills
A relentless interview to sharpen a plan or design.
improve-codebase-architecture
mattpocock/skills
Scan a codebase for deepening opportunities, present them as a visual HTML report, then grill through whichever one you pick.
handoff
mattpocock/skills
Compact the current conversation into a handoff document for another agent to pick up.
domain-modeling
mattpocock/skills
Build and sharpen a project's domain model. Use when discussing codebase terminology, writing or editing a GLOSSARY.md, or recording or editing an ADR.
codebase-design
mattpocock/skills
Shared vocabulary for designing deep modules. Use when the user wants to design or improve a module's interface, find deepening opportunities, decide where a seam goes, make code more testable or AI-navigable, or when another skill needs the deep-module vocabulary.
diagnosing-bugs
mattpocock/skills
Diagnosis loop for hard bugs and performance regressions. Use when the user says "diagnose"/"debug this", or reports something broken/throwing/failing/slow.