Stop wasting time on slow pre-commit hooks with this Rust alternative
GitHub RepoImpressions1k

Stop wasting time on slow pre-commit hooks with this Rust alternative

@githubprojectsPost Author

Project Description

View on GitHub

Speed Up Your Git Workflow with Prek: Rust-Powered Pre-Commit Hooks

If you've ever found yourself staring at your terminal, waiting for a slow pre-commit hook to finish, you know the frustration. That precious flow state gets interrupted by a sluggish script that checks your code. It's a common pain point, especially when those hooks are written in interpreted languages that add noticeable overhead to every commit.

Enter Prek—a tool built in Rust that aims to eliminate that wait. It's not just another linter or formatter; it's a framework designed to make your pre-commit hooks fast by default. If you're tired of the delay, this might be the alternative you've been looking for.

What It Does

Prek is a command-line tool that helps you run checks on your staged Git files before a commit. Think of it as a runner for your pre-commit validations, but one that's built with performance as a primary goal. You define tasks (like checking for large files, running a linter, or ensuring no debug statements are present) in a simple configuration file, and Prek executes them against the files you're about to commit. Its core job is to be the fast, reliable engine that powers your commit-quality gate.

Why It's Cool

The obvious win here is speed. Being written in Rust, Prek starts up and runs tasks significantly faster than hooks written in, say, Python or Node.js, especially for simple file checks. This means less time waiting and more time coding.

But beyond raw speed, its design is pragmatic. It focuses on the staged files in your Git repository, which is what you actually care about in a pre-commit context, rather than scanning the entire project unnecessarily. This targeted approach is more efficient by nature.

It's also straightforward to set up. You configure your checks in a prek.toml file, specifying commands or scripts to run and which file patterns they apply to. This keeps your hook logic declarative and separate from your Git hooks themselves, making it easier to manage and share across your team.

How to Try It

Getting started is pretty standard for a Rust tool. You can install it using Cargo, Rust's package manager.

cargo install prek

Once installed, navigate to your Git repository and create a prek.toml file in the root. Here's a basic example to get you started:

[[tasks]]
name = "check-large-files"
command = "sh"
args = ["-c", "find ${STAGED_FILES} -size +5M | wc -l | grep -q 0"]
failure_message = "Found files larger than 5MB"

Then, you need to integrate it with Git. Create a file at .git/hooks/pre-commit (make sure it's executable) with the following content:

#!/bin/sh
prek run

That's it. Now your pre-commit hook will use Prek to run the tasks you defined.

Final Thoughts

Prek tackles a specific, real problem—slow pre-commit hooks—with a simple and effective solution. It won't replace complex linter setups, but for a set of fast, reliable sanity checks (file size, syntax, trailing whitespace, etc.), it's a great fit. If your team's commit hooks are becoming a bottleneck, giving Prek a spin could be a worthwhile experiment. It's the kind of tool that does one job and does it well, quietly making your daily workflow a bit smoother.

@githubprojects

Back to Projects
Project ID: 21ce4887-4b87-424f-9d7f-861692f09217Last updated: February 6, 2026 at 04:37 AM