Ah ok, that is some good sleuthing! I would expect someone can help with this, I can’t, sorry. But its trivial to get the context key…
Here check this out, this guy’s question is diferent but he gives code for getting the key
https://forums.modx.com/thread/104944/how-to-get-the-name-of-the-current-context
$modx->context->key
$modx->resource->context_key