Is it possible to disable or temporarily suspend pyRevit hooks?

Hi everyone,

I’m running into an issue with pyRevit hooks and wanted to ask if there’s a recommended way to disable or suspend them.

I have several hooks implemented (e.g. doc_changed, app_init, and a few others). Some of my scripts are getting triggered recursively, and because the hooks fire again during execution, the scripts end up failing or behaving unpredictably.

My questions are:

  • Is there a way to globally disable pyRevit hooks (temporarily or conditionally)?

  • Or is there a best practice for preventing hooks from re-triggering scripts that are already running?

  • For example, is there a built-in mechanism, context flag, or pattern to safely ignore hook execution during certain operations?

Any guidance, examples, or recommended patterns would be greatly appreciated.

Thanks in advance!

Not really a true ‘disable’ but I read the state of a custom global variable at the start of all my hooks and exit/continue based on its state True/False. This way very little of the hook actually runs if triggered. A simple toggle button sets the state.

script.get_envvar(‘PAUSEHOOKS_ENV_VAR’)
script.set_envvar(‘PAUSEHOOKS_ENV_VAR’, new_state)