Mark Shinners, 45, had just completed an appointment at Addenbrooke’s Hospital when he stole a bike in the hospital grounds after removing a D-lock.
He had taken another bike to ride to that point.
Appearing before Peterborough Magistrates’ Court in custody on Monday, Shinners pleaded guilty to the theft last Friday.
He also admitted breaching a Criminal Behaviour Order imposed because of similar previous offences.
Solicitor Simon Rice, mitigating, said his client had been released from custody the previous Monday without the necessary arrangements for a methadone script.
Shinners, of no fixed address, then went to Addenbrooke’s following a concern for his safety incident at Queen Anne Terrace car park in Cambridge.
Mr Rice said: “He was told ‘if all you want is your script, we are not here to help you with that.’
“He did not want to resort to using drugs again but, caught in a vicious cycle, he stole the cycle in view of security standing there.
“He was begging for help because this is happening. The only thing he knows how to do is get arrested.
“He needs help.”
A probation officer told the court that an arrangement had been made for the defendant to collect a script at 4pm that day and he had not attended subsequent appointments.
Imprisoning Shinners for eight weeks for the theft and 12 weeks for the court order breach, to run concurrently, District Judge Ken Sheraton told him: “I’m looking at your record and the drug problem you’ve had for a good number of years.
“If you wanted to get rid of it you had plenty of time to do it.”