Bring a large saucepan of salted water to the boil, add the spaghetti and cook until al dente.
Meanwhile, heat a large cast-iron or heavy-based saucepan over medium heat. Add the oil and shallot, then grate in the garlic using a microplane. Add the chilli and a pinch of salt and cook for a few minutes, stirring constantly, until the onion has softened.