Put the oil in a medium pot over medium-high heat. When it’s hot, add the onion and season with salt and pepper. Cook, stirring occasionally, until it’s soft and golden brown, 8 to 10 minutes. Add the cumin, chili powder, and cayenne pepper, and cook, stirring, until fragrant, about 1 minute.
Add the beans to the pot, along with a few tablespoons of their cooking liquid (or water) if they’re very dry. Cook, stirring occasionally, until the beans are heated through, 3 to 5 minutes. Turn off the heat and mash with a potato masher or partially purée with an immersion blender. Taste and adjust the seasoning, and serve hot or warm. (Store leftover refried beans in an airtight container in the refrigerator for up to several days.)
