Caramelize the onions. Melt 4 Tbsp butter in a large soup pot over medium heat, then add 3 lbs sliced onion, 2 tsp Kosher salt, and 1 tsp sugar. Stir well, then cover and cook for 15 minutes, stirring occasionally. Remove the lid, then continue cooking for 40-60 minutes, stirring as needed, until the onions are uniformly caramelized. If you notice the onions getting too brown or sticking to the pan, reduce the heat to medium-low.
Add the liquid. Increase the heat to medium-high, then pour in 1 cup red wine and 1 Tbsp Cognac, if using, being sure to scrape the bottom of the pan to release any browned bits. Cook for 1 minute. Pour in 8 cups of low-sodium chicken stock (or veggie or beef stock), then add thyme sprigs, 2 bay leaves, remaining ½ tsp Kosher salt, and ½ tsp freshly ground black pepper. Bring to a boil over high heat, then reduce and simmer over medium-low for about 30 minutes. Taste, then adjust seasoning as needed.
Make the croutons. Preheat an oven to 375°F/190°C. Place baguette cubes on a rimmed baking sheet lined with parchment or foil, then drizzle with 3 Tbsp olive oil and a little Kosher salt. Bake for 7-10 minutes, or until crispy. Remove and set aside. Increase the oven temperature to 475°F/245°C.
Bake with cheese and bread. Discard the thyme and bay leaves, then ladle the soup into individual serving bowls placed on a rimmed baking sheet. Top with as many croutons as you like (any extras can be served on the side), then divide the Gruyere (or Comte) between the bowls and sprinkle on top. Carefully transfer to the oven, then bake for 5-10 minutes, or until the cheese is melted. Cool slightly, then serve immediately! For a beautiful presentation, garnish each soup with a little fresh thyme.