We develop a theory of moral behavior, individual and collective, based on a general model of identity in which people care about “who they are” and infer their own values from past choices. The model sheds light on many empirical puzzles inconsistent with earlier approaches. Identity investments respond nonmonotonically to acts or threats, and taboos on mere thoughts arise to protect beliefs about the “priceless” value of certain social assets. High endowments trigger escalating commitment and a treadmill effect, while competing identities can cause dysfunctional capital destruction. Social interactions induce both social and antisocial norms of contribution, sustained by respectively shunning free riders or do-gooders.