Where do custom Drush hooks go? I am attempting to sanitize my database as described in this Acquia guide.

For my site, I need to sanitize all the usernames as well; I would like to sanitize the usernames exactly the same as the e-mail addresses.

The guide suggests using a hook such as this:

&lt;?php
/**
* Implementation of hook_drush_sql_sync_sanitize().
*/
function modulename_drush_sql_sync_sanitize($source) {
    $query = "UPDATE content_type_profile SET field_primary_email_email = CONCAT(SUBSTRING_INDEX(field_primary_email_email,'@', 1), '@example.com');";

    $query .= "UPDATE content_type_profile SET field_work_phone_value = SUBSTRING(FLOOR(RAND() * 1000000000000) WHERE uid NOT IN  SELECT uid FROM users_roles WHERE rid=3) AND uid &gt; 0 FROM 1 FOR 12)  WHERE field_work_phone_value IS NOT NULL;";

   drush_sql_register_post_sync_op('my-sanitize-id', dt('Sanitize email addresses and phone numbers'), $query);
}
?&gt;


But since this is for Drush, I don't know where to put the hook.  I tried modifying the code and  adding it to an enabled module on my site, but when I ran sql-sanitize, it didn't pick up the hook.

This is what I did.  In MYMODULE/MYMODULE.module, I added the following code:

/**
* Implementation of hook_drush_sql_sync_sanitize().
*/
function MYMODULE_drush_sql_sync_sanitize($source) {
    $query = "UPDATE user SET name = CONCAT(SUBSTRING_INDEX(name,'@', 1), '@example.com');";


   drush_sql_register_post_sync_op('my-sanitize-id', dt('Sanitize user names'), $query);
}
?&gt;
Looking at the drush code this is the function that looks for the "hooks"

drush_command_invoke_all('drush_sql_sync_sanitize', 'default');


following the path at the end is calling to:

drush_commandfile_list()


which is going to look for hooks implementations in the next folders:


The "/path/to/drush/commands" folder.
Folders listed in the 'include' option (see example.drushrc.php).
The system-wide drush commands folder, e.g. /usr/share/drush/commands
The ".drush" folder in the user's HOME folder.
/drush and sites/all/drush in current Drupal site.
Folders belonging to enabled modules in the current Drupal site.


So as @Clive suggested probably MYMODULE.drush.inc and MYMODULE_drush_sql_sync_sanitize should work.