Editor plugin that runs all the time?

I would like to create an editor plugin that runs all the time while Unity runs, which also gets events like when the hierarchy or project changes (much like a custom EditorWindow subclass but without the UI). I don’t want to present anything to the user, I just want to have it in the background listening for changes and doing some magic if needed. Is this possible and if yes how would I achieve this?

To answer my own question, the solution is a normal class and adding the [InitializeOnLoad] attribute to it. To get the callbacks like OnHierarchyChange fired, also add the appropriate callbacks to EditorApplication. Example:

using UnityEngine;
using UnityEditor;

[InitializeOnLoad]
public class Foobar
{
	static Foobar()
	{
		EditorApplication.hierarchyWindowChanged += OnHierarchyChange;
	}

    static void OnHierarchyChange()
    {
        // Blahblah
    }
}

Whine: The InitializeOnLoad attribute is not listed in the Attribute list of the Unity reference manual… At least not directly.

Well, in general you have to keep in mind that when ever Unity compiles a script in your project, everything is reloaded and recreated. That means everything that is in managed code will be reset whenever something compiles. There are almost no editor specific events where you can hook into. The best place would be a AssetModificationProcessor or AssetPostprocessor. In there you can register a delegate on EditorApplication.update or any other delegate you can find on EditorApplication.