Melt the butter in a large pot over medium heat. Add the onions and cook until deeply caramelized, about 25 minutes.
Sprinkle the flour over the onions and cook, stirring, for 2 minutes.
Gradually stir in the chicken broth, scraping up any browned bits from the bottom of the pot.
Add the shredded chicken and simmer for 20 minutes. Season with salt and pepper.
Ladle the soup into oven-safe bowls. Top each with a baguette slice and a generous sprinkle of Gruyère cheese.
Broil until the cheese is bubbly and golden. Serve immediately.