Preheat the oven to 350°F (175°C) and line a baking sheet with parchment paper. This helps the cookies bake evenly and prevents sticking.
In a medium bowl, whisk together the flour, baking powder, baking soda, salt, and cinnamon until evenly combined.
In a large bowl, beat the softened butter, brown sugar, and granulated sugar until the mixture becomes pale and fluffy, about 2–3 minutes.
Beat in the eggs one at a time, then mix in the vanilla extract. Fold in the grated carrots until evenly distributed.
Gradually add the dry ingredients to the wet mixture and stir just until no dry flour remains. Fold in the chopped pecans or walnuts if using.
Scoop about 2 tablespoons of dough onto the prepared baking sheet, leaving about 2 inches between cookies. Lightly flatten each mound with the back of a spoon.
Bake for 10–12 minutes, until the edges are lightly golden while the centers still look slightly soft.
Let the cookies cool on the baking sheet for 5 minutes before transferring them to a wire rack. Frost only after they have cooled completely, if desired.