Setup Pre Commit
Step-by-step Husky pre-commit setup that wires lint-staged, Prettier, typecheck, and tests into commits.
- CCM score
- 66 of 100
- skills.sh installs
- 5.8K
- GitHub stars
- 6.2K
- last updated
- Aug 21, 2026
Own this skill? Claim it
What it does
- Covers detecting the package manager, installing
husky,lint-staged, andprettier, and initializing the hook - Creates
.husky/pre-commit,.lintstagedrc, and a default.prettierrconly when no Prettier config exists - Runs lint-staged on staged files first, then the full typecheck and test scripts, skipping any script the repo lacks
- Designed for JavaScript repositories that want formatting and checks enforced at commit time
Install
$ npx -y skills add vinvcn/mattpocock-skills-zh-cn --skill setup-pre-commit -yInstalls into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.
Files
设置 Pre-Commit Hooks
这会配置什么
- Husky pre-commit hook
- lint-staged 对所有 staged files 运行 Prettier
- Prettier config(如果缺失)
- pre-commit hook 中的 typecheck 和 test scripts
步骤
1. 检测 package manager
检查 package-lock.json (npm)、pnpm-lock.yaml (pnpm)、yarn.lock (yarn)、bun.lockb (bun)。使用存在的那个。不清楚时默认 npm。
2. 安装依赖
作为 devDependencies 安装:
husky lint-staged prettier
3. 初始化 Husky
npx husky init
这会创建 .husky/ dir,并向 package.json 添加 prepare: "husky"。
4. 创建 .husky/pre-commit
写入这个文件(Husky v9+ 不需要 shebang):
npx lint-staged
npm run typecheck
npm run test
Adapt:把 npm 替换为检测到的 package manager。如果 repo 的 package.json 没有 typecheck 或 test script,就省略对应行并告知用户。
5. 创建 .lintstagedrc
{
"*": "prettier --ignore-unknown --write"
}
6. 创建 .prettierrc(如果缺失)
只有没有 Prettier config 时才创建。使用这些 defaults:
{
"useTabs": false,
"tabWidth": 2,
"printWidth": 80,
"singleQuote": false,
"trailingComma": "es5",
"semi": true,
"arrowParens": "always"
}
7. 验证
Details
- Repository
- github.com/vinvcn/mattpocock-skills-zh-cn
- Categories
- Git & Releases, Testing & QA, Code Review & Quality
- First seen
- Jun 3, 2026
Questions
What does the setup-pre-commit skill do?
It sets up Husky pre-commit hooks in the current repository, wired to lint-staged with Prettier, a typecheck script and a test script. It also creates a Prettier config if the project has none. The skill fits when you want formatting, typechecks and tests to run on every commit.
How do I install the setup-pre-commit skill?
Run npx -y skills add vinvcn/mattpocock-skills-zh-cn --skill setup-pre-commit -y in your project. After that, the agent can install husky, lint-staged and prettier, run husky init, and write the pre-commit hook file.
Where does setup-pre-commit rank in its category?
It sits in the Git & Releases category on Claude Marketplaces and ranks in the top 50 there. Other skills in that category include triage, git-guardrails-claude-code, caveman-commit and pr.
What does the skill need before it runs?
The repository needs a package.json, and the skill detects the package manager from its lock file, using npm when unclear. If the package.json has no typecheck or test script, the skill leaves that line out and tells you.
More from vinvcn/mattpocock-skills-zh-cn
All 24- Migrate To Shoehorn5.8K
- Teach5.6K
- Grilling4.9K
- Domain Modeling4.6K
- Code Review4.6K
- Ask Matt4.6K
- Diagnosing Bugs4.6K
- Implement4.5K
- Codebase Design4.5K
- Research4.4K
- Writing Shape3.9K
- Writing Fragments3.9K
- Writing Beats3.9K
- Grill Me7.1K
- Grill With Docs6.7K
- Setup Matt Pocock Skills6.4K
- Handoff6.3K
- Tdd6.3K
- Improve Codebase Architecture6.2K
- Prototype6.2K
- Triage6K
- Git Guardrails Claude Code5.8K
- Scaffold Exercises5.8K
Similar to Setup Pre Commit
More Git & Releasesgit-hooks-setupSkillaj-geddes/useful-ai-prompts452 installsGit hook setup covering Husky and pre-commit that enforces linting, commit messages, secret scanning, and tests.
smart-commitSkillrohitg00/pro-workflow201 installsStructured pre-commit workflow that runs lint, typecheck, and changed-file tests before drafting a conventional commit.
code-formatter-installerSkillpatricio0312rev/skills279 installsStep-by-step setup of Prettier, ESLint, EditorConfig, and git hooks across JS, Python, Go, and Rust projects.
eslint-prettier-configSkillpatricio0312rev/skills1.1K installsConfigures ESLint and Prettier as one consistent setup for TypeScript and React code quality.
huskyPluginccplugins/awesome-claude-code-plugins1K starsSets up and manages Husky Git hooks by configuring pre-commit hooks, establishing commit message standards, integrating with linting tools, and ensuring code qu