In a large skillet, heat the oil over medium heat. Add the onions and cook, stirring occasionally, until browned and almost caramelized, about 25 minutes. Add the cilantro stems, shrimp, anchovies, Thai chiles, fried shallots, and whole lime leaves. Cook, stirring, for 2 minutes. Stir in the fish sauce and sugar and mix until evenly combined. Remove from the heat and add thinly sliced lime leaves.
Transfer to a large baking pan and spread into a thin and even layer. Bake until the mixture is dry and crispy, 1 to 1 1/2 hours. Remove from the oven and let cool completely. Wearing gloves, crumble the chiles and toss to evenly combine.
Serve immediately or store in an airtight container (like a lidded glass jar) at room temperature for up to 2 weeks.