the before_compile event receives the Query object at the point it starts to turn it into a SQL construct. When this happens, it's in response to having said something like "query.all()". So there's no **kwarg that's specific to an operation like that.
instead, when you want to send "messages" to event handlers like before_compile(), you have to do it by altering the state of the Query itself. Your suggestion to say "query.filter_by(archived=True)" is actually such a state change, which would be altering the "_criterion" attribute to include the "archived=True" criteria, but to consume this attribute to search for this specific criteria would be tedious and possibly error prone.
instead, you can stick with a simpler way to change the state of the Query in a way that you can detect inside your event handler easily. Probably the simplest is to use the query.execution_options() method, where you can add arbitrary keys and values that can be read later on:
query = query.execution_options(include_archived=True)
in your handler you can check it just like thisL
def filter_archived(query):
if not query.get_execution_options().get("include_archived", False):
# modify the query