This release is a pre-release and may not be stable for production use.
pre-commit-snippets
A pre-commit hook that automatically syncs markdown snippets from a central repository into your documentation files.
Features
- Marker-based replacement: Uses
<!-- SNIPPET-START: name -->/<!-- SNIPPET-END -->markers to identify replaceable blocks - SHA-256 caching: Only rewrites blocks when the central snippet has actually changed, avoiding unnecessary file churn
- Automatic staging: Modified files are automatically staged for commit
- Branch/tag support: Pin snippets to a specific branch or tag
- Dry-run mode: Preview changes without modifying files
- Debug logging: Detailed logging for troubleshooting
Installation
Using pre-commit framework
Add this to your .pre-commit-config.yaml:
repos:
- repo: https://github.com/RemoteRabbit/pre-commit-snippets
rev: v1.0.4 # Use the latest tag
hooks:
- id: snippet-sync
Manual installation
- Clone this repository
- Create a
.pre-commit-snippets-config.yamlconfiguration file (see below) - Run
python main.pybefore committing
Configuration
Create a .pre-commit-snippets-config.yaml file in your repository root:
# URL of the repository containing your snippets (required)
snippet_repo: https://github.com/your-org/snippets.git
# Branch or tag to use (optional, default: default branch)
snippet_branch: main
# Subdirectory within the snippet repo where snippets are stored (optional)
snippet_subdir: snippets
# File extension for snippet files (optional, default: .md)
snippet_ext: .md
# Path for the snippet hash cache file (optional, default: .snippet-hashes.json)
cache_path: .snippet-hashes.json
# List of files to process (required)
target_files:
- README.md
- docs/CONTRIBUTING.md
- docs/SECURITY.md
Usage
In your markdown files, wrap the areas you want to sync with snippet markers:
# My Project
<!-- SNIPPET-START: license-notice -->
This content will be replaced with the contents of `license-notice.md` from your snippet repo.
<!-- SNIPPET-END -->
## Other content...
When the hook runs, it will:
- Clone the snippet repository (shallow clone)
- Find all
SNIPPET-START/SNIPPET-ENDmarker pairs - Replace the content between markers with the corresponding snippet file
- Cache hashes to avoid rewriting unchanged blocks
- Stage any modified files
Command Line Options
pre-commit-snippets [OPTIONS]
# or
python main.py [OPTIONS]
| Option | Description |
|---|---|
--dry-run |
Preview changes without modifying files |
--verbose, -v |
Print info-level logs (files being processed, updates) |
--debug |
Print debug-level logs with timestamps (commands, hashes, paths) |
--config PATH |
Path to config file (default: .pre-commit-snippets-config.yaml in repo root) |
Examples
# Normal run
pre-commit-snippets
# Preview what would change
pre-commit-snippets --dry-run
# See detailed processing info
pre-commit-snippets --verbose
# Debug issues with full detail
pre-commit-snippets --debug
Cache File
The hook creates a .snippet-hashes.json file to track which snippets have been applied. You should commit this file to avoid unnecessary rewrites on other machines.
Project Structure
pre-commit-snippets/
├── main.py # CLI entry point
├── pre_commit_snippet/
│ ├── __init__.py # Package init
│ ├── cache.py # Hash computation and caching
│ ├── cli.py # Argument parsing and main logic
│ ├── config.py # Configuration loading
│ ├── git.py # Git operations
│ ├── logging.py # Logging configuration
│ └── snippet.py # Snippet replacement logic
└── tests/
└── test_main.py # Test suite
Development
See CONTRIBUTING.md for development setup, conventional commits, and release process.
License
MIT
Release files for pre-commit-snippets 2.0.1.dev20260421173534
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pre_commit_snippets-2.0.1.dev20260421173534.tar.gz | 13.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pre_commit_snippets-2.0.1.dev20260421173534-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 26.4 kB
Release files / pre_commit_snippets-2.0.1.dev20260421173534.tar.gz
| Download URL | pre_commit_snippets-2.0.1.dev20260421173534.tar.gz |
|---|---|
| Size | 13.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
27dbb09fe69fa9c24d4c7219732d961c59374b106df9efd0482ec17be6c7333e
|
|
BLAKE2b-256 checksum How to use checksums |
add5301426eda38136e40e76b4fa5f741fe8415b6160ef020f333f5015b79b65
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 21, 2026.
Transparency logRelease files / pre_commit_snippets-2.0.1.dev20260421173534-py3-none-any.whl
| Download URL | pre_commit_snippets-2.0.1.dev20260421173534-py3-none-any.whl |
|---|---|
| Size | 12.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a7b53b2b3d9835d84d52e678d979ca8f3b513c7eb5f5c7b4133ef0574064a896
|
|
BLAKE2b-256 checksum How to use checksums |
94a9af3e4e56d898c94fff6f6b4a5cde55719678a674c6f4f68c4929bee22333
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 21, 2026.
Transparency log