From c207eb4aabd8c305adb99a3261045a8f220ae7b0 Mon Sep 17 00:00:00 2001 From: Matthew Hughes Date: Thu, 26 Mar 2026 20:48:48 +0000 Subject: [PATCH] Document `PRE_COMMIT` environment variable Document this variable, exposed since `v2.5.0`[1], as a way to determine if `pre-commit` is running. Because It took a bit of searching in the `pre-commit` repo to discover the existence of this variable. Link: https://github.com/pre-commit/pre-commit/commit/2f25085d60bf953fea457a3240c91886145dbcc5 [1] --- sections/advanced.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sections/advanced.md b/sections/advanced.md index 442dbff1..02c637ea 100644 --- a/sections/advanced.md +++ b/sections/advanced.md @@ -885,3 +885,8 @@ tag or SHA) and will cache based on that. Using a branch name (or `HEAD`) for the value of [`rev`](#repos-rev) is not supported and will only represent the state of that mutable ref at the time of hook installation (and will *NOT* update automatically). + +## Detecting when `pre-commit` is running + +You can check for the existence of the `PRE_COMMIT` environment variable within +a hook to determine if it's being run from `pre-commit`.