We study optimal team design. In our model, a principal assigns either heterogeneous agents to a team (a diverse team) or homogenous agents to a team (a specialized team) to perform repeated team production. We assume that specialized teams exhibit a productive substitutability (e.g., interchangeable efforts with decreasing returns to total effort), whereas diverse teams exhibit a productive complementarity (e.g., cross-functional teams). Diverse teams have an inherent advantage in fostering desirable implicit/relational incentives that team members can provide to each other (tacit cooperation). In contrast, specialization both complicates the provision of cooperative incentives by altering the punishment agents can impose on each other for short expected career horizons and fosters undesirable implicit incentives (tacit collusion) for long expected horizons. As a result, expected compensation is first decreasing and then increasing in the discount factor for specialized teams, while expected compensation is always decreasing in the discount factor for diverse teams. We use our results to develop empirical implications about the association between team tenure and team composition, pay-for-performance sensitivity, and team culture.