BackgroundCocaine use is broadly associated with risky sexual behavior potentially through elevated sexual desire. Understanding the within-person effects of cocaine on sexual desire and risky sexual behavior and the modification of HIV infection may inform primary and secondary HIV interventions. MethodsWe conducted a mobile health (mHealth) study in a community sample of males and females with (n = 28) and without (n = 32) HIV who use illicit stimulant drugs. Participants completed ecological momentary assessments (EMAs) and daily diaries over 28 days. Mixed effects models were employed to examine the within-person association of cocaine use with sexual desire and risky sexual behavior. ResultsParticipants completed 3505 EMA responses, with 36 % involving recent cocaine use, including powder and/or crack cocaine. They completed 1427 daily diary responses, with cocaine use reported on 49 % of these days and sexual behavior on 21 % of these days. Sexual desire was highest in the first hour since cocaine use and gradually decreased with time. Sexual desire was lowest when participants had not used any cocaine in the past 6 h, and it correlated positively with the amount of use. Participants were more likely to have risky sexual behavior on days they used cocaine. These associations were similar for participants with and without HIV. ConclusionThis study demonstrates the dynamic and proximal effects of cocaine use on sexual desire and risky sexual behavior. Our findings support the development of HIV prevention interventions that utilize mHealth technology to reduce sexual risk behavior among persons who use stimulant drugs.