How do I change the site name in the .theme file?
In a *.theme file this would be difficult to find all places where the site name may end up. This is much easier to do it in settings.php right at the start:

settings.php:

if ($_SERVER['REQUEST_URI'] == '/abc/def') {
  $config['system.site']['name'] = 'abc-def';
}