The purpose of this study is to determine if the medication lofexidine, taken together with buprenorphine or methadone, is more effective at reducing opioid craving, use and stress response than buprenorphine or methadone alone, and to see if this effect is different for men and women. Participants are randomly assigned to add either lofexidine or placebo to their buprenorphine or methadone treatment for five weeks. They return at the end of five weeks to participate in an opioid imagery task and stress task. Throughout the study, participants complete "CREMA" sessions (Cue Reactivity Ecologic Momentary Assessment) using an iPhone app three times a day. These sessions include looking at stressful and neutral pictures and rating stress and craving.