Preheat oven to 400°F (200°C). Slice the squash in half and scoop out the seeds.
Brush the inside with olive oil, place cut-side down on a baking sheet, and roast for 40 minutes.
Let it cool slightly, then use a fork to shred the inside into noodle-like strands.
In a pan, sauté garlic and onion in olive oil until fragrant.
Add crushed tomatoes, tomato paste, oregano, basil, salt, and pepper. Simmer for 10 minutes.
Stir in fresh basil and red pepper flakes if using.
Spoon marinara over spaghetti squash strands and serve warm.