Set a main-menu item as active with custom code I want to set a menu item of the main menu as active (class="active").

I'm specifically looking for a hook or function, not a contrib module.

I have seen recommendations for Context, and I have looked in the module code, but it uses hooks which I cannot find on the API-Site.
If you simply want to add the 'active' class to a menu item you could do it in the code before printing the menu.
If you want the menu item to also act like an active item you could use menu_tree_set_path() that was supposedly added in Drupal 7.9.

In earlier versions and Drupal 6 I used this:

function mymodule_init() {
  $item = menu_get_item($_GET['q']);
  $item['href'] = 'node/1';
  menu_set_item(NULL, $item);
}


However both options just add the 'active-trail' (not 'active') class(es), but that should suffice in most cases.