How can I understand when a node is being edited or viewed?
In this case you'd want to look at parts of the url. The easiest way to do that would be passing in additional classes from a preprocess function in the .theme file, and by looking at the URL path:

$current_path = \Drupal::service('path.current')-&gt;getPath();
$path_args = explode('/', $current_path);

if ($path_args[0] == 'node' &amp;&amp; $path_args[2] == 'edit') {
  // add classes
}


This would be similar to using the arg() function from previous versions.