Singer Pete Doherty has been bailed and told to stay at a rehabilitation clinic after pleading guilty to five counts of possessing drugs.
Doherty will be sentenced in September
The Babyshambles star, 27, appeared at Thames Magistrates' Court in London.
It follows his arrest in April, just hours after receiving a community order for previous drug offences.
District Judge Alison Rose ordered Doherty to stay at a clinic in Southgate, north London, until sentencing on 4 September.
She told him her options "most definitely include the possibility of custody".
Doherty, of Haggerston, east London, pleaded guilty to charges of possessing heroin, cocaine - some of which was crack cocaine - and cannabis.
He also admitted to one count of possession on 7 August, when he was found with a crack pipe and a small amount of crack cocaine.
He is due to have his community order reviewed on the sentencing date.
Doherty's counsel Sean Curran told the court that while the singer was "positively" engaged with treatment a negative test result was a "realisable and achievable goal".
He said there had been "substantial and tangible improvement" in his physical health as well as progress in reducing his drug use.
Mr Curran added that Doherty had been clearing the substances out of his car when arrested on 20 April, and had "forgotten" about the crack pipe when arrested on 7 August.
"He has only hurt himself by his drug addiction. He is in a position that he can fund it without criminal activity," Mr Curran added.
Applying for bail, Mr Curran said: "It's clear he's a very talented musician, unfortunately the chaotic world that encompasses that has led to some of his downfall."
Asking that Doherty be allowed to appear at a concert in Clapham, south London, on 27 August, Mr Curran said: "If he is unable to perform, it may have a serious detrimental impact on his career.
"If his career is taken from him that could lead to potential lapses, and relapses should he recover from his addiction."
Doherty will be able to appear at the concert, but otherwise he will have to observe a 2200-0800 curfew.