I am expecting that drush_get_commands() will return all drush commands including from modules such as 'feature', but it is not when called within my Drush custom command. How to retrieve all drush commands available for the current drupal instance including ones provided from custom modules? Thank You

1 Answer 1


It is important to remember that drush_get_commands() is sensitive to the bootstrap level that your command has reached. You must have bootstrapped a Drupal site before Drush commands associated with modules in that site are available via drush_get_commands(). There are several requirements for this to be true.

  1. You must have selected a Drupal site when you ran your custom Drush command, either by using a site alias (e.g. drush @mysite), or via commandline options (e.g. drush --root=/path/to/drupal --uri=mysite.org), or by setting your current working directory to the same directory that contains the settings.php file for your site.

  2. Your custom command must declare a bootstrap level that is high enough to bootstrap a Drupal site. For example, DRUSH_BOOTSTRAP_DRUSH is not sufficient, but DRUSH_BOOTSTRAP_FULL is. If your command has not bootstrapped to a high enough level, you may call drush_bootstrap_max() to finish bootstrapping the selected site.

  3. Drush commands will only be loaded for enabled modules.

If you do all of these things, then you should see all commands for all modules when you call drush_get_commands(). If you don't, try drush cc drush to clear the commandfile cache.

(As a side note, do not use drush_get_commands() as a way to call other Drush commands from your custom commandfile. Instead, use drush_invoke_process().)

  • Excellent explanation! Thank you Greg. For those who like to bootstrap into DRUSH_BOOTSTRAP_DRUSH without Drupal site selected at the start but then based on some condition bootstrap into some drupal site of your choice, there is API drush_bootstrap_max_to_sitealias($loaded_alias_record). Drush is awesome!Thank You
    – latvian
    Aug 31, 2014 at 15:25
  • drush_set_context('DRUSH_SELECTED_DRUPAL_ROOT', $site_record['root']); i guess you have to set the root manually before bootstrapping via drush_bootstrap_max_to_sitealias
    – latvian
    Aug 31, 2014 at 17:56
  • Your site alias should define 'root' and 'uri', so just calling drush_bootstrap_max_to_sitealias() should be enough. Just make sure that the alias you select is for a local site; this function won't do the right thing for remote site aliases, of course. Aug 31, 2014 at 22:52
  • Thank you Greg....the alias provided did have the 'root' and 'uri' specified and it was not remote or maybe i missed something, but thank you
    – latvian
    Sep 4, 2014 at 17:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.