There is scarcely any other field in which women are so underrepresented as they are in computer sciences. Socio-psychological literature suggests that students are more likely to engage in domains they perceive as fitting their identity (Kessels, Heyder, Latsch & Hannover, 2014). As the Science, Technology, Engineering, and Mathematics (STEM) prototype (e.g. a typical student interested in computer sciences) is linked with agentic-masculine traits (e.g. competitiveness) and not with communal-feminine traits (e.g. helping others), most girls regard STEM subjects as incompatible with their self-view. We investigated whether coding courses for students linked with communal goals were more attractive to girls compared to coding courses associated with agentic goals. We assumed greater self-to-prototype similarity would mediate the link between the students' gender and their interest in learning to code. Based on structural equation modeling with 459 German ninth- and tenth-grade students, our results confirm our hypothesis: girls showed greater interest in learning to code if course descriptions were focused on communal goals, while boys showed greater interest under the agentic-goal condition. As expected, self-to-prototype similarity mediated the relationship between gender and interest in the communal coding course. With regard to the agentic coding course, we found only a partial mediating effect. Our results provide recommendations for the development of STEM interventions that encourage the inclusion of female students.