Preheat your oven to 180°C/350°F (160°C/320°F fan).
In a large skillet over medium heat, pour in the olive oil. Allow it to heat before adding the mushrooms. Season with salt and black pepper and stir occasionally until the mushrooms release their liquid, about 8 minutes.
If using butter, add it now to the pan. Allow it to melt and coat the mushrooms. Add the garlic and thyme, sauté for another minute, then remove from heat.
Prepare a baking sheet by lining it with parchment paper. Unroll the puff pastry onto the lined sheet, score a 1-inch border around the edges, and prick the center with a fork.
Spread the sautéed mushrooms evenly inside the border. Top with the grated cheese.
In a small bowl, beat the egg for the egg wash and brush it around the border of the puff pastry.
Bake for 12 to 15 minutes until the puff pastry is golden brown. Remove from the oven and sprinkle with chili flakes if desired.
Allow it to cool slightly before slicing into 6 squares and serving warm.