pre-commit
Skill4 starsChanged 7 months agoMITView on GitHub
Guide for using pre-commit hooks to validate code formatting, linting, and security checks before commits. You MUST load this skill when using pre-commit hooks for validation.
7 other projects use a version of this.
Adopted by
Most recently taken up by
- benyoskovitz/claude-code-workflowtheir own version, first seen Sep 24, 2026
- RealDougEubanks/ClaudeMarketplacetheir own version, first seen Sep 10, 2026
- autowarefoundation/autoware-harnesstheir own version, first seen Aug 26, 2026
- Pradnyeshp/Claude-Skillstheir own version, first seen Jul 6, 2026
- alex-voloshin-dev/ai-skillstheir own version, first seen May 17, 2026
- Docat0209/SoloForgetheir own version, first seen Apr 4, 2026
Other versions7 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 7
- undeadlist/claude-code-agents★ 149same name
- benyoskovitz/claude-code-workflow★ 8same name
- autowarefoundation/autoware-harness★ 4same name
- alex-voloshin-dev/ai-skills★ 2same name
- Pradnyeshp/Claude-Skills★ 2same name
- Docat0209/SoloForge★ 1same name
- RealDougEubanks/ClaudeMarketplace★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository124 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .github/AGENTS.mdAGENTS.md
- .github/workflows/AGENTS.mdAGENTS.md
- .vscode/AGENTS.mdAGENTS.md
- .github/copilot-instructions.mdCopilot instructions
- agent-log-analysisSkill
- agent-mdSkill
- agent-md-writerSkill
- agent-skill-md-writerSkill
- agentskillsSkill
- agents-md-writerSkill
- ai-prompt-writerSkill
- ansibleSkill
- apache-airflow-apiSkill
- apache-airflow-dagsSkill
- astro-cliSkill
- astronomer-docsSkill
- awesome-copilotSkill
- brainstorm-agent-runsSkill
- brainstorm-github-prSkill
- brainstormSkill
- catSkill
- chrome-devtoolsSkill
- claude-docsSkill
- codeqlSkill
- code-reviewSkill
- code-tourSkill
- coding-standard-writerSkill
- context-aware-opsSkill
- copilot-cliSkill
- copilot-docsSkill
- critical-thinkingSkill
- datadog-agentSkill
- datadog-apiSkill
- datadog-mcpSkill
- datadog-monitorsSkill
- datadog-pulumiSkill
- devcontainerSkill
- dictationSkill
- direnvSkill
- dockerfileSkill
- dockerSkill
- docs-reviewSkill
- docs-writerSkill
- dot-claudeSkill
- dotfilesSkill
- dot-githubSkill
- editorconfigSkill
- fact-writerSkill
- gdpr-compliantSkill
- gh-agent-taskSkill
- gh-apiSkill
- gh-aw-compileSkill
- gh-aw-firewall-debugSkill
- gh-aw-firewallSkill
- gh-aw-newSkill
- gh-awSkill
- gh-aw-troubleshootingSkill
- gh-codespaceSkill
- gh-issueSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
11 rules. 0 are common, 6 are distinctive, and 5 are very specific to this project.
0
Common
Most of the 7 edited versions we read keep these.
6
Distinctive
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 30
Skip only when necessary: Use --no-verify or SKIP=<hook-id> sparingly.
- Distinctive: line 35
When writing complex, multi-file integration tests that require a full environment boot (pre-commit is for fast, isolated, file-level …
- Very specific: line 36
If the repository has explicitly opted out of pre-commit in favor of a different localized linting orchestration tool (like npm run lint).
- Very specific: line 121
Custom config: Create .gitleaks.toml in repository root to:
- Distinctive: line 123
Add custom secret patterns
- Very specific: line 149
Baseline file: Create .secrets.baseline to store known false positives:
- Very specific: line 161
Custom config: Create .j2lint.toml or .j2lint.yaml for custom linting rules (rarely needed).
- Distinctive: line 191
Create script in repository:
- Distinctive: line 226
Create script with uv shebang:
- Distinctive: line 276
Document dependencies: If script requires specific tools, document in script comments or repo README.
- Distinctive: line 327
YAML formatting conflicts: Run yamllint before yamlfix to catch syntax errors first:
“Common” is measured: kept by at least 6 in 10 of the 7 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Pre-commit
<!-- markdownlint-disable MD013 -->Expert guide for pre-commit framework usage, configuration, and custom hook development. Focus on autonomous validation, diagnostics, and fix workflows.
When to Use
- Analyzing why pre-commit validation blocked a user's local git commit.
- Running mass syntax/lint checks on the repository proactively.
- User needs to configure, update, or bypass a pre-commit hook (markdownlint, yamllint, etc.).
Core Principles
- Staged files only: Pre-commit runs exclusively on staged (cached) files, not the entire working directory.
- Fast feedback: Catch issues before commit/push to reduce CI failures and review cycles.
- Configuration-driven: Hooks reference external config files (.yamllint, .markdownlint.yaml, etc.) for consistency.
- Idempotent fixes: Many hooks auto-fix issues (e.g., trailing-whitespace, end-of-file-fixer); re-stage and re-run to pass.
- Skip only when necessary: Use
--no-verifyorSKIP=<hook-id>sparingly; prefer fixing issues over bypassing validation.
When Not to Use
- When writing complex, multi-file integration tests that require a full environment boot (pre-commit is for fast, isolated, file-level checks).
- If the repository has explicitly opted out of pre-commit in favor of a different localized linting orchestration tool (like
npm run lint). - For enforcing subjective architectural patterns that cannot be statically analyzed.
Common Pitfalls
- Bypassing the Cache: Running
pre-commit runon unstaged files and wondering why the linter didn't catch the errors (it only checks the git index by default). - Auto-Fix Loops: Forgetting to
git addthe files that pre-commit auto-formatted (like trailing whitespace fixes), causing the hook to fail repeatedly. - Mismatched Python Versions: Running a local Python hook that requires
>=3.11on a system with an older default Python, causing the hook script to crash.
Testing Commands
Run all hooks on all files (recommended before committing):
pre-commit run --all-filesRun all hooks on staged files only (default behavior):
pre-commit runRun specific hook on all files:
pre-commit run <hook-id> --all-filesRun specific hook on staged files:
pre-commit run <hook-id>Examples for individual linters:
pre-commit run yamllint --all-files # YAML linting
pre-commit run markdownlint --all-files # Markdown linting
pre-commit run flake8 --all-files # Python linting
pre-commit run black --all-files # Python formatting
pre-commit run ansible-lint --all-files # Ansible linting
pre-commit run actionlint --all-files # GitHub Actions workflow linting
pre-commit run gitleaks --all-files # Secret scanning
pre-commit run detect-secrets --all-files # Alternative secret detection
pre-commit run trailing-whitespace -a # Fix trailing spaces (auto-fix)
pre-commit run end-of-file-fixer -a # Fix EOF newlines (auto-fix)Run hook on specific file:
pre-commit run <hook-id> --files <file-path>Configuration Dependencies
Pre-commit hooks reference external dotfiles for linting rules. Key dependencies in this repository:
| Hook ID | Config File | Purpose | Notes |
yamllint | .yamllint | YAML linting rules | Max line length: 120, enforces consistent formatting |
markdownlint | .markdownlint.yaml | Markdown style rules | Max line length: 120, allows consistent heading styles |
yamlfix | .yamlfix.toml | YAML auto-formatting | Line length: 110, forces block-style sequences |
flake8 | CLI args in .pre-commit-config.yaml | Python linting | Max line length: 120 (via --max-line-length=120) |
black | Defaults | Python code formatting | Uses Black's default line length (88) |
ansible-lint | Embedded defaults | Ansible best practices | No custom config file in this repo |
actionlint | Embedded defaults | GitHub Actions validation | No custom config file in this repo |
gitleaks | Optional .gitleaks.toml | Secret scanning patterns | Can override default rules (see below) |
detect-secrets | Optional .secrets.baseline | Secret detection baseline | Can store known false positives |
| All hooks | .editorconfig | Cross-editor consistency | Indent size: 2 for YAML/JSON, 4 for others; LF line endings |
Why trailing-whitespace excludes YAML: The trailing-whitespace hook in the repository's .pre-commit-config.yaml
excludes \.ya?ml$ (YAML files) because yamllint handles trailing spaces for YAML files with warning-level enforcement,
avoiding duplicate checks.
Optional Configuration Files
Some hooks support optional config files to customize behavior beyond defaults:
gitleaks
Default: Uses embedded ruleset for secret detection (API keys, passwords, tokens).
Custom config: Create .gitleaks.toml in repository root to:
- Add custom secret patterns
- Exclude specific paths or files
- Allowlist known false positives
Example .gitleaks.toml:
[extend]
useDefault = true
[[rules]]
id = "custom-api-key"
description = "Custom API Key Pattern"
regex = '''MYAPI-[A-Z0-9]{32}'''
[allowlist]
paths = [
'''.*test.*''',
'''.*example.*'''
]detect-secrets
Default: Scans all files for high-entropy strings and common secret patterns.
Baseline file: Create .secrets.baseline to store known false positives:
detect-secrets scan > .secrets.baselineFuture runs compare against baseline; only new secrets trigger failures.
j2lint
Default: Validates Jinja2 template syntax using embedded rules.
Custom config: Create .j2lint.toml or .j2lint.yaml for custom linting rules (rarely needed).
Update Process
Update all hooks to latest versions:
pre-commit autoupdateThis updates .pre-commit-config.yaml with the newest rev for each repo. Always review diff and test after updating:
pre-commit run --all-filesUpdate specific hook:
pre-commit autoupdate --repo https://github.com/<owner>/<repo>Freeze at specific version: Manually edit .pre-commit-config.yaml and pin rev to a specific tag/commit.
Creating Custom Local Hooks
Pre-commit supports custom hooks via local repository scripts. Add to .pre-commit-config.yaml:
Example: Local Shell Script Hook
- Create script in repository:
#!/usr/bin/env bash
# File: .github/scripts/check-copyright.sh
set -euo pipefail
for file in "$@"; do
if ! grep -q "Copyright $(date +%Y)" "$file"; then
echo "Missing copyright header in $file" >&2
exit 1
fi
done- Make executable:
chmod +x .github/scripts/check-copyright.sh- Add to
.pre-commit-config.yaml:
- repo: local
hooks:
- id: check-copyright
name: Verify copyright headers
entry: .github/scripts/check-copyright.sh
language: system
types: [python]Example: Local Python Script Hook
- Create script with uv shebang:
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.11"
# dependencies = [
# "pyyaml",
# ]
# ///
import sys
import yaml
def validate_yaml_keys(filepath):
with open(filepath) as f:
data = yaml.safe_load(f)
if 'required_key' not in data:
print(f"Missing required_key in {filepath}", file=sys.stderr)
return False
return True
if __name__ == '__main__':
all_valid = all(validate_yaml_keys(f) for f in sys.argv[1:])
sys.exit(0 if all_valid else 1)- Make executable:
chmod +x .github/scripts/validate-yaml-keys.py- Add to
.pre-commit-config.yaml:
- repo: local
hooks:
- id: validate-yaml-keys
name: Check YAML required keys
entry: .github/scripts/validate-yaml-keys.py
language: system
types: [yaml]Local Hook Best Practices
- Use
language: systemfor scripts that require executables in PATH (bash, python, etc.). - Pass filenames as args: Pre-commit passes matching files as arguments to
entrycommand. - Exit codes matter: Exit 0 for success, non-zero for failure.
- Keep scripts idempotent: Hook may run multiple times; avoid side effects.
- Document dependencies: If script requires specific tools, document in script comments or repo README.
Diagnostics and Troubleshooting
Hook fails on specific file:
pre-commit run <hook-id> --files <file-path> --verboseSkip hooks temporarily (commit without validation):
git commit --no-verify -m "message"Skip specific hook (run all except one):
SKIP=<hook-id> git commit -m "message"Check pre-commit installation and config:
pre-commit --version
pre-commit validate-configClean pre-commit cache (fixes stale hook errors):
pre-commit clean
pre-commit install --install-hooksDebug hook execution:
pre-commit run <hook-id> --verbose --all-filesCommon Failure Patterns
Auto-fixable hooks modified files: Re-stage and re-run:
git add -u
pre-commit runYAML formatting conflicts: Run yamllint before yamlfix to catch syntax errors first:
pre-commit run yamllint --all-files
pre-commit run yamlfix --all-filesMarkdown line length violations: Reflow paragraphs manually or use editor formatter (VS Code: "Format Document").
Secret detection false positives:
- For gitleaks: Add to
.gitleaks.tomlallowlist. - For detect-secrets: Update
.secrets.baselinewithdetect-secrets scan --baseline .secrets.baseline.
What to Avoid
- Committing with
--no-verifywithout documenting reason. - Modifying
.pre-commit-config.yamlwithout testing changes locally. - Bypassing hooks to "save time" — fixing issues post-merge costs more.
- Running hooks on untracked files (pre-commit ignores them; stage first).
Limitations
- Pre-commit only validates staged files; unstaged changes are ignored.
- Hooks run sequentially; large repos may experience slower commit times.
- Some hooks (e.g., yamlfix) may conflict with manual formatting preferences.
- Custom local hooks require executable scripts in repository; not portable across forks without dependencies.
Related Skills
- tdd: You MUST load this skill when executing test tasks, designing tests, doing TDD, or verifying system behavior.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

