Cook the spaghetti in salted water. Reserve about 100 ml of the cooking water before draining.
Peel and finely chop the onion and garlic. Set aside.
Slice the ham into strips. Set aside.
Wash, clean, and slice the mushrooms. Sauté them in a dry pan until they release their moisture and start to brown.
Drizzle with olive oil, then add the onion and garlic. Sauté until softened. Season with salt and pepper.
Add the ham and fry lightly for a few minutes.
Pour in the tomato puree. Season with salt, oregano, and basil. Add the reserved pasta water and simmer everything together.
Serve mixed with the cooked spaghetti.
If it fits your diet, sprinkle grated cheese on top before serving.