Prepare the onions by slicing thinly and setting aside.
Heat olive oil in a large pan over medium heat. Add the sliced onions and a pinch of salt.
Caramelize the onions for 25-30 minutes, stirring occasionally.
While the onions are caramelizing, cook the spaghetti according to package directions until al dente.
Reserve 1 cup of pasta water, then drain the spaghetti.
Once the onions are caramelized, add the drained spaghetti to the pan along with chili oil and a bit of reserved pasta water.
Adjust the seasoning, adding more chili oil or salt to taste.
Serve immediately, garnished with fresh parsley and grated Parmesan if desired.