Cook the zucchini: Heat the olive oil in a large pan over medium heat. Add the diced zucchini, chopped shallot, lightly smashed whole pieces of garlic, salt, black pepper, and red pepper flakes. Stir to combine and cook for 3 minutes.
Cover and cook: Reduce the heat to medium-low and cover. Cook for 40 minutes, stirring every 10 minutes, until the zucchini is very soft and jammy. Gently press the zucchini with a wooden spoon as it cooks to help it break down.
Cook the pasta: When the zucchini is nearly finished, cook the spaghetti in boiling salted water until 1 minute shy of al dente. Reserve 2 cups of pasta water.
Finish the sauce: Add the pasta, Pecorino Romano, Parmesan cheese, butter, and ½ cup pasta water to the zucchini mixture. Toss continuously until a glossy sauce forms, adding additional pasta water as needed.
Serve: Stir in the lemon juice. Divide among bowls and top with basil and additional cheese, if desired.
Video
Notes
Zucchini: I leave the skin on for color and texture. The zucchini will break down as it cooks, so the exact size of the pieces is not important.
Pasta water: Reserve plenty before draining. The starchy pasta water is essential for creating a silky, cohesive sauce. You may not use all 2 cups, but it's better to have extra on hand. I ended up using most of it.
Cheese: Pecorino Romano adds a sharper, saltier flavor while Parmesan is milder and nuttier. I like using both for balance, but you can use all Parmesan or all Pecorino Romano if preferred. Freshly grated cheese melts more smoothly than pre-shredded cheese.
Cooking the zucchini: If the zucchini starts sticking to the pan or looks dry while cooking, add a splash of water and reduce the heat slightly. The zucchini should become soft and jammy, not browned or burnt.
Basil: I used Thai basil, but sweet basil works well too.