In a large skillet, heat the olive oil until shimmering.
Add onions and a pinch of salt, sautéing until soft and translucent—about 5 minutes.
Stir in garlic, cumin, and chili powder (if using). Cook until fragrant, about 1 minute.
Pour in the beans and cover with water. Stir, then lower the heat to very low and let simmer for 20 minutes.
Add lime juice and adjust salt to taste.
For a chunkier texture, mash with a potato masher. For smooth, creamy refried beans, use an immersion blender.