I’d like to propose an optional safety setting for Git hooks. When enabled, Git would check for an active hook before running it in a repository that the user has not approved. It would show the hook’s path and ask whether to run it once, trust the current hooks for this repository, or decline. This would help when a tool or setup step installs hooks from files supplied by a project. The check should happen immediately before execution, so it also covers hooks installed after a repository was cloned. For scripts inside the working tree, Git should ask again if the approved script changes. The default behavior could remain unchanged, with this protection enabled by an explicit user setting.
[RFC] Optional per-repository consent before running local hooks
3 messages between Sep 29, 2026 and Sep 29, 2026, from Dmytro Lymarenko, Junio C Hamano, brian m. carlson.
Plain Markdown or JSON for tools and agents.
Re: [RFC] Optional per-repository consent before running local hooks
Dmytro Lymarenko <dmytro.lymarenko@gmail.com> writes:
Show 12 quoted lines
> I’d like to propose an optional safety setting for Git hooks. When > enabled, Git would check for an active hook before running it in a > repository that the user has not approved. It would show the hook’s > path and ask whether to run it once, trust the current hooks for this > repository, or decline. > This would help when a tool or setup step installs hooks from files > supplied by a project. The check should happen immediately before > execution, so it also covers hooks installed after a repository was > cloned. For scripts inside the working tree, Git should ask again if > the approved script changes. > The default behavior could remain unchanged, with this protection > enabled by an explicit user setting.
One thing that immediately comes to mind is that, if the "tool or setup step" is allowed to install hooks from files supplied by a project, it is unclear what prevents it from also approving these hooks on the user's behalf (or, rather, leaving the same "clue" that your proposed mechanism uses to record that the user approved execution of these hooks).
Re: [RFC] Optional per-repository consent before running local hooks
On 2026-09-29 at 04:23:43, Dmytro Lymarenko wrote:
Show 5 quoted lines
> I’d like to propose an optional safety setting for Git hooks. When > enabled, Git would check for an active hook before running it in a > repository that the user has not approved. It would show the hook’s > path and ask whether to run it once, trust the current hooks for this > repository, or decline.
In addition to what Junio said, we need to consider what happens if Git operates noninteractively. For instance, a CI system or a Docker container.
Show 5 quoted lines
> This would help when a tool or setup step installs hooks from files > supplied by a project. The check should happen immediately before > execution, so it also covers hooks installed after a repository was > cloned. For scripts inside the working tree, Git should ask again if > the approved script changes.
I agree this is undesirable behaviour from a project and I typically consider installing hooks or other external software from the repository without the user's consent to be malicious. Installing hooks from things like Git LFS I consider less of a problem because I have installed that software and configured it on my system, so I presumably want that behaviour.
The problem also becomes where to store this information because Git doesn't have any sort of data store to store per-user information other than the config file and as Junio mentioned, if the repository can install hooks, it can also set config.
What may be kind of equivalent is to set `core.hooksPath` to `/dev/null` in the global config and then choose to set it to `hooks` or `.git/hooks` in the local config if you want that. Or you can do the reverse and use `core.hooksPath=/dev/null` in the local config for poorly behaved repositories. Of course, the repo can override that, but if it does that, then I'd just report it as malicious to its hosting provider.
-- brian m. carlson (they/them) Toronto, Ontario, CA