In a medium bowl, whisk the flour, baking powder, and salt.
In a stand mixer fitted with the paddle attachment, beat the butter and sugar on medium speed until light and fluffy, 2 to 3 minutes.
Add the eggs one at a time, mixing on medium speed after each addition until incorporated.
Mix in the vanilla and then the coconut until well combined.
With the mixer on low speed, gradually add the flour mixture and mix just until combined.
The dough will be sticky.
With the mixer still on low, mix in the chocolate chips (and almonds, if using) .
Cover the bowl with plastic wrap and refrigerate for 30 minutes.
Position a rack in the center of the oven and heat the oven to 350°F.
Line a large cookie sheet with parchment.
Divide the dough into equal halves and place on the cookie sheet.
Working on the sheet, shape each half into a loaf about 10 inches long, 3 inches wide, and 3/4 inch high.
Bake until the tops are browned, cracked, and crusty, and spring back slightly when gently pressed, 30 to 35 minutes.
Cool about 30 minutes on the cookie sheet.
Reduce the oven temperature to 325°F.
Transfer each loaf to a cutting board and with a sharp serrated bread knife, cut 1/2-inch slices crosswise on the diagonal.
When slicing, hold the sides of the loaf near each cut to keep the slices neat.
Put the slices cut side down on the cookie sheet and bake until the biscotti are dried and the cut surfaces are lightly browned, 15 to 20 minutes. Transfer the cookie sheet to a rack and let the biscotti cool completely. The biscotti may give slightly when pressed but will harden as they cool.