PurposeWhile spontaneous and voluntary knowledge contribution in online communities promotes value co-creation, dysfunctional knowledge behaviors hamper the effectiveness and development of such communities. The study conceptualizes physicians' proactive knowledge sharing and knowledge withholding behaviors in physician-driven online health communities (OHCs) and integrates the theories of role identity as well as communal and exchange relationships to understand the root causes and motivations behind these two types of knowledge behaviors.Design/methodology/approachThe authors collected survey data from 166 users from one of the largest physician-driven OHCs in China and applied the covariance-based structural equation modeling approach to test the hypotheses.FindingsThe findings suggest that (1) physicians' professional role identity had a positive indirect effect on proactive knowledge sharing behaviors through communal motivation, and work pressure weakened this indirect effect; and (2) professional role identity had a negative indirect impact on knowledge withholding behaviors through exchange motivation.Originality/valueThis study extends proactive knowledge sharing and knowledge withholding behaviors from the organizational management domain to the online environment, exploring the underlying causes and motivations behind both behaviors in the unique context of physician-driven OHCs. The findings offer practical suggestions for the effective management of OHC platforms, as well as policy implications that respond to the workforce shortage of healthcare providers, a crisis that is unfolding globally.