diff --git a/includes/drush.inc b/includes/drush.inc
index 717a7b4..35d4918 100644
--- a/includes/drush.inc
+++ b/includes/drush.inc
@@ -937,14 +937,19 @@ function drush_remote_command() {
   // option will be set when the site alias is processed.
   // @see drush_sitealias_check_arg
   $remote_host = drush_get_option('remote-host');
+  // Get the command early so that we can allow commands to directly handle remote aliases if they wish
+  $command = drush_parse_command();
+  if (isset($command) && array_key_exists('handle-remote-commands', $command)) {
+    return FALSE;
+  }
   if (isset($remote_host)) {
     $args = drush_get_arguments();
-    $command = array_shift($args);
+    $command_name = array_shift($args);
     $remote_user = drush_get_option('remote-user');
 
     // Force interactive mode if there is a single remote target.  #interactive is added by drush_do_command_redispatch
     drush_set_option('interactive', TRUE);
-    drush_do_command_redispatch($command, $args, $remote_host, $remote_user);
+    drush_do_command_redispatch($command_name, $args, $remote_host, $remote_user);
     return TRUE;
   }
   // If the --site-list flag is set, then we will execute the specified
@@ -969,7 +974,7 @@ function drush_remote_command() {
         return TRUE;
       }
     }
-    $command = array_shift($args);
+    $command_name = array_shift($args);
     $multi_options = drush_get_context('cli');
     $backend_options = array();
     if (drush_get_option('pipe')) {
@@ -987,7 +992,7 @@ function drush_remote_command() {
       $multi_options['reserve-margin'] = $max_name_length + strlen($label_separator);
       foreach ($site_list as $alias_name => $alias_record) {
         $backend_options['output-label'] = str_pad($alias_name, $max_name_length, " ") . $label_separator;
-        $values = drush_do_site_command($alias_record, $command, $args, $multi_options, $backend_options);
+        $values = drush_do_site_command($alias_record, $command_name, $args, $multi_options, $backend_options);
       }
     }
     else {
@@ -995,8 +1000,8 @@ function drush_remote_command() {
         $backend_options['interactive'] = TRUE;
       }
       foreach ($site_list as $alias_name => $alias_record) {
-        drush_print(dt("!site >> !command", array('!command' => $command . ' ' . implode(" ", $args), '!site' => $alias_name)));
-        $values = drush_do_site_command($alias_record, $command, $args, $multi_options, $backend_options);
+        drush_print(dt("!site >> !command", array('!command' => $command_name . ' ' . implode(" ", $args), '!site' => $alias_name)));
+        $values = drush_do_site_command($alias_record, $command_name, $args, $multi_options, $backend_options);
         drush_print($values['output']);
       }
     }
diff --git a/includes/sitealias.inc b/includes/sitealias.inc
index bcb7da2..6e65fb0 100644
--- a/includes/sitealias.inc
+++ b/includes/sitealias.inc
@@ -22,6 +22,7 @@ function drush_sitealias_check_arg() {
 
   // Test to see if the first arg is a site specification
   if (_drush_sitealias_set_context_by_name($args[0])) {
+    drush_set_context('DRUSH_TARGET_SITE_ALIAS', $args[0]);
     array_shift($args);
     // We only need to expand the site specification
     // once, then we are done.
