Bring a large pot of salted water to a boil. Add the cavatelli and cook as the label directs. Reserve 1/4 cup cooking water, then drain.
Meanwhile, heat the olive oil in a large skillet over medium heat. Add the garlic, 1/2 teaspoon salt and the red pepper flakes and cook until the garlic is soft but not browned, 3 to 4 minutes. Stir in the basil and tomatoes with their juice. Increase the heat to high and cook until the sauce is thickened, about 10 minutes.
Add the cavatelli and the reserved cooking water to the skillet; cook, tossing, until warmed through, 2 to 3 minutes. Divide among bowls and top with the ricotta and pecorino. Season with salt and pepper.