Varies a bit. In Peds, the department is quite large. My PD didn’t do much clinical work, so her giving a student a letter of recommendation would be weird. But the clerkship directors saw all the students on their third year rotation work clinically, so they might be a reasonable source. My clerkship director med school was a geneticist—I never worked with him clinically. The PD was half hospitalist and half ID, so we worked with her some, but we also did our Peds rotations at other hospitals, so it wasn’t guaranteed. So had I not specifically rotated on ID, and she happened to be the attending on, I might not have been able to get a letter from her.
I think it matters more in more procedural based specialties—surgery, anesthesiology, etc. But IM, FM, and Peds often have such large departments that are broken up so much that you may not see some of the big wigs in the residency program as a student.