setup-pre-commit

setup-pre-commit is a skill for Claude Code, Codex from devcxl/mattpocock-skills-zh. It costs 70 tokens per session (744 once invoked), scanned A, original, MIT.

A setup guide for Git pre-commit checks, which run automatically before a commit is created. It configures Husky, lint-staged, Prettier, type checking, and tests in a repository.

In plain words
What is it for?
Use it to add or configure pre-commit hooks, format staged files, and run a repository’s type-checking and test scripts before commits.
Why use it?
It catches formatting errors, type errors, and test failures before they enter version control. It also avoids setting up these checks by hand.

Skill for Claude CodeCodex

Part of the mattpocock-skills-zh plugin — 37 skills shipped together

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/devcxl/mattpocock-skills-zh/setup-pre-commit
Any agent
npx skills add devcxl/mattpocock-skills-zh --skill setup-pre-commit
Clone the repo
git clone --depth 1 https://github.com/devcxl/mattpocock-skills-zh

Made for: Claude Code, Codex.

Or install mattpocock-skills-zh, the plugin that ships this one along with the rest of its 37 skills.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for setup-pre-commit

README.md
[![agentmods](https://agentmods.dev/badge/skills/devcxl/mattpocock-skills-zh/setup-pre-commit.svg)](https://agentmods.dev/skills/devcxl/mattpocock-skills-zh/setup-pre-commit)
Your own site
<a href="https://agentmods.dev/skills/devcxl/mattpocock-skills-zh/setup-pre-commit"><img src="https://agentmods.dev/badge/skills/devcxl/mattpocock-skills-zh/setup-pre-commit.svg" alt="Measured on agentmods" height="20"></a>
Per session 70 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 744 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00070 $0.00744
Opus 5 $0.00035 $0.00372
Sonnet 5 $0.00014 $0.00149
Haiku 4.5 $0.00007 $0.00074

Measured 5d ago against content hash 019d16766d33, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

setup-pre-commit scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 5d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/misc/setup-pre-commit/SKILL.md · 92 lines

What it actually says

设置 Pre-Commit 钩子

将要设置的内容

  • Husky pre-commit 钩子
  • lint-staged 对所有暂存文件运行 Prettier
  • Prettier 配置(如果缺失)
  • typechecktest 脚本在 pre-commit 钩子中运行

步骤

1. 检测包管理器

检查 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/ 目录并在 package.json 中添加 prepare: "husky"

4. 创建 .husky/pre-commit

写入以下内容(Husky v9+ 不需要 shebang):

npx lint-staged
npm run typecheck
npm run test

适配:将 npm 替换为检测到的包管理器。如果仓库的 package.json 中没有 typechecktest 脚本,则省略对应行并告知用户。

5. 创建 .lintstagedrc

{
  "*": "prettier --ignore-unknown --write"
}

6. 创建 .prettierrc(如果缺失)

仅当不存在 Prettier 配置时才创建。使用以下默认值:

{
  "useTabs": false,
  "tabWidth": 2,
  "printWidth": 80,
  "singleQuote": false,
  "trailingComma": "es5",
  "semi": true,
  "arrowParens": "always"
}

7. 验证

  • .husky/pre-commit 存在且可执行
  • .lintstagedrc 存在
  • package.json 中的 prepare 脚本为 "husky"
  • prettier 配置存在
  • 运行 npx lint-staged 验证其是否正常工作

8. 提交

暂存所有更改/创建的文件,并使用消息提交:Add pre-commit hooks (husky + lint-staged + prettier)

这将触发新的 pre-commit 钩子执行:是一个很好的冒烟测试,验证一切正常。

注意事项

  • Husky v9+ 不需要在钩子文件中加 shebang
  • prettier --ignore-unknown 会跳过 Prettier 无法解析的文件(如图片等)
  • pre-commit 钩子先运行 lint-staged(快速,仅处理暂存文件),然后运行完整的 typecheck 和 test
Files

What ships with it

1 file beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 5d ago First seen · 92 lines · 70 tokens per session scan A 019d16766d33

Subscribe to this mod's changes

setup-pre-commit is a skill published in the GitHub repository devcxl/mattpocock-skills-zh (299 stars, last pushed 9d ago), licensed MIT. It adds 70 tokens to every session and 744 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories