Bring a large pot of salted water to a boil.
Cook pasta according to package instructions, adding broccoli during the last 3–4 minutes.
Reserve ¼ cup pasta water, then drain pasta and broccoli.
Heat olive oil in a large pan over medium heat.
Add garlic and sauté until fragrant, about 30 seconds.
Add pasta and broccoli to the pan. Toss to coat.
Add reserved pasta water as needed to loosen the sauce.
Season with salt, pepper, and red pepper flakes if using.
Remove from heat and stir in Parmesan and lemon if desired.
Serve warm.