The acting head of the UK’s court service has apologised after a black barrister was mistaken for a defendant three times in one day.

Alexandra Wilson, who grew up in Essex, is a criminal and family barrister and author of In Black And White - an account of her experiences of race and class in the justice system.

She tweeted that she was “absolutely exhausted” after staff at the court repeatedly failed to recognise she worked in the legal profession.

Her tweets quickly went viral, drawing accusations of racism within the UK’s court system.

Kevin Sadler, the acting chief executive of Her Majesty’s Courts and Tribunals Service apologised to Ms Wilson and said it was “totally unacceptable behaviour” and he would be investigating the role of his staff in the incident.

Ms Wilson said when she arrived at court on Wednesday the security officer first asked for her name so he could find it on the list of defendants.

“I explained I was a barrister. He apologised and guided me through security,” she said.

“At this point I tried to shrug it off as an innocent mistake.”

After meeting with her client, she then tried to enter the courtroom to discuss the case with the prosecutor.

She said: “At the door a member of the public told me not to go into the courtroom. I asked why and she said because it’s a court, only lawyers can go in. She said I was a journalist.

“The usher (the one person who recognised I was a barrister today) said to ignore her and to head on in.

“As I opened the door, a solicitor/barrister said I needed to wait outside court and said the usher (who, btw, was next to me) would come outside and sign me in and the court would call me in for my case. I explained I’m a barrister. She looked embarrassed and said 'oh. I see.'

“She turned back around and I walked towards the prosecutor, ready to have our conversation. Before I got there the clerk, VERY loudly, told me to leave the courtroom and said the usher would be out shortly. Before I could respond she then asked if I was represented.

“I, AGAIN, explained that I am a defence barrister trying to speak to the prosecutor. She looked at me, said 'oh right, ok' and continued with what she was doing.”

Following the incidents, Ms Wilson said she has lodged a formal complaint: “This really isn’t ok though. I don’t expect to have to constantly justify my existence at work.”

Mr Sadler responded to Ms Wilson’s twitter thread and said: “I’m investigating the role of my staff and contractors as a matter of urgency. This is not the behaviour anyone should expect and certainly does not reflect our values.”

It comes after official figures revealed people from black, Asian and minority ethnic (BAME) backgrounds are less likely to be successful when applying to become a judge, and only 9% are senior barristers.

Last week a Ministry of Justice report found BAME people “over-represented in applications for judicial appointment” but are “less likely to be successful”.

Industry leaders have called for the legal profession to diversify to better represent the public.