In a large pot of boiling salted water, cook spaghetti until al dente; reserve 1/2 cup pasta water. Add shrimp to pot, and stir. Immediately drain spaghetti and shrimp, and set aside (the shrimp will continue to cook).
In same pot, heat oil over medium. Add garlic, rosemary, and red-pepper flakes. Cook, stirring, until garlic is golden, 1 to 3 minutes.
Remove from heat; return pasta and shrimp to pot. Add lemon juice and enough pasta water to create a thin sauce that coats pasta. Season with salt and pepper, and serve.