Preheat oven to 350°F (175°C) and line baking sheets with parchment paper.
Whisk together flour, baking soda, cinnamon, nutmeg, and salt in a bowl.
Beat butter, brown sugar, and granulated sugar until light and fluffy.
Mix in egg and vanilla extract until combined.
Gradually add dry ingredients into wet mixture until just combined.
Fold in grated carrots and walnuts if using.
Scoop tablespoon-sized dough portions onto baking sheet, spacing evenly.
Bake for 10–12 minutes until edges are set and centers are soft.
Let cookies cool completely on a wire rack.
Beat cream cheese and butter until smooth and creamy.
Add powdered sugar and vanilla, beating until fluffy.
Spread or pipe frosting onto one cookie and sandwich with another.