Change record status: 
Project: 
Introduced in branch: 
11.5.x
Introduced in version: 
11.5.0
Description: 

A new static method, \Drupal\Core\Recipe\RecipeRunner::isApplying() has been added so that code can determine if it is being run when a recipe is being applied.

For example:

use \Drupal\Core\Recipe\RecipeRunner;

function hook_install($is_syncing): void {
  // Set general module variables.
  $variable = RecipeRunner::isApplying() ? 'barbar', 'bar';
  \Drupal::state()->set('my_module.foo', $variable);
}
Impacts: 
Module developers
Site templates, recipes and distribution developers