Cette page est affichée en anglais. Une traduction française est en cours.
SkillsApr 14, 2026·3 min de lecture

pre-commit — A Framework for Managing Git Hook Scripts

pre-commit manages and installs multi-language Git hooks from a YAML file. It runs linters, formatters, and checks before commits reach CI — catching issues early with zero manual setup per developer.

Prêt pour agents

Installation agent prête

Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
step-1.md
Commande d'installation directe
npx -y tokrepo@latest install 69a51c48-37b5-11f1-9bc6-00163e2b0d79 --target codex

À exécuter après confirmation du plan en dry-run.

TL;DR
pre-commit installs and runs linters, formatters, and checks as Git hooks from a single YAML config file.
§01

What it is

pre-commit is a framework for managing and installing multi-language Git hooks. It reads a .pre-commit-config.yaml file and runs configured hooks (linters, formatters, security checks) before each commit.

pre-commit targets development teams who want to catch issues locally before code reaches CI. It supports hooks written in Python, Node.js, Go, Rust, Ruby, and more -- all managed from one config file.

§02

How it saves time or tokens

pre-commit catches formatting errors, trailing whitespace, YAML syntax issues, and linting violations before they become CI failures. This eliminates round-trip time waiting for remote CI to flag trivial issues. New developers get all hooks installed with a single pre-commit install command.

§03

How to use

  1. Install pre-commit and initialize hooks:
pip install pre-commit
pre-commit install
pre-commit run --all-files
  1. Create a .pre-commit-config.yaml in your repo root.
  1. Commit as normal. Hooks run automatically on each git commit.
§04

Example

# .pre-commit-config.yaml
repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.6.0
    hooks:
      - id: trailing-whitespace
      - id: end-of-file-fixer
      - id: check-yaml
  - repo: https://github.com/astral-sh/ruff-pre-commit
    rev: v0.6.9
    hooks:
      - id: ruff
        args: [--fix]
      - id: ruff-format
  - repo: https://github.com/pre-commit/mirrors-prettier
    rev: v3.1.0
    hooks:
      - id: prettier
        types_or: [javascript, typescript, json, yaml, markdown]
§05

Related on TokRepo

§06

Common pitfalls

  • Hook environments are cached in ~/.cache/pre-commit/. Clear this cache if hooks behave unexpectedly after version updates.
  • Large repos may experience slow hook runs. Use the files or exclude regex in hook config to limit scope.
  • pre-commit hooks run on staged files only by default. Use pre-commit run --all-files for full-repo checks in CI.

Questions fréquentes

What languages does pre-commit support for hooks?+

pre-commit supports hooks written in Python, Node.js, Ruby, Go, Rust, Swift, .NET, Docker, and shell scripts. Each hook declares its language and pre-commit manages the runtime environment automatically.

How do I skip pre-commit hooks temporarily?+

Use git commit --no-verify or the SKIP environment variable (e.g., SKIP=ruff git commit). This is useful for WIP commits but should not be used as a habit since it defeats the purpose of the hooks.

Can pre-commit run in CI pipelines?+

Yes. Run 'pre-commit run --all-files' in your CI script. This checks every file in the repository, not just staged changes. Many teams use pre-commit.ci as a hosted service that runs hooks automatically on pull requests.

How does pre-commit handle hook dependencies?+

pre-commit creates isolated virtual environments for each hook based on the declared language. Python hooks get their own venv, Node.js hooks get their own node_modules. This prevents dependency conflicts between hooks.

What is the difference between pre-commit and husky?+

Husky is a Node.js-specific Git hooks manager. pre-commit is language-agnostic and manages hook runtimes for any language. pre-commit also provides a curated ecosystem of community hooks via its registry.

Sources citées (3)

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires