This paper develops a model of child custody based on an incomplete-contract approach to the allocation of property rights. Because of the presence of transaction costs in marriage, altruistic parents cannot contract upon the investments they make into their children, but can reduce the resulting inefficiencies by determining ex ante the parent who would be allocated custody in case they divorce. We show that: (i) the optimal allocation of custodial rights depends on both preferences and technological factors; (ii) custodial rights can be allocated either to the parent who values the benefits from child welfare more or, viceversa, to the parent with the lowest valuation; (iii) if one parent?s investment is significantly more important than the other parent?s investment, then sole custody is preferred to joint custody and it should be allocated to the parent whose investment is relatively more important; and (iv) if the importance of the parents? investments is sufficiently similar and if the differences in parents? valuations of child quality are large, then joint custody is optimal with the lowvaluation parent receiving a relatively greater share, because the other parent would invest in the child anyway while the low-valuation parent would be endowed with greater bargaining power. The implications of these results are then interpreted in the context of current custody laws, discussed in relation to empirical estimates of some of the parameters underlying the optimal custody rule, and used to question the skepticism surrounding prenuptial contracts.