Warm 2 tablespoons olive oil in an oven-safe skillet over medium heat for 1-2 minutes. Add diced onion and cook for 4-5 minutes until translucent and edges soften. Do not rush this step to avoid crunchy onions.
Stir in diced tomatoes with their juice, salt, and black pepper. Let the mixture simmer uncovered for 5-7 minutes, stirring occasionally, until the liquid reduces and tomatoes become a thick, chunky sauce.
Add minced garlic and stir for 1 minute until fragrant but not browned. Maintain medium heat to prevent burning the garlic.
Lower heat to medium-low. Use a spoon to make 4 shallow wells in the tomato mixture, spacing them evenly. Crack one egg into each well. Sprinkle optional cheese over the eggs if using.
Cover the skillet with a lid or foil. Cook for 3-5 minutes until the egg whites are set but the yolks remain soft and jiggly. Remove from heat, sprinkle chopped fresh basil or parsley, and serve immediately.