Extract common before hook to shared_context