A boy was caught with a "Rambo-style" knife at school months before he allegedly killed a 15-year-old student, a court has heard.
Tashaûn Aird was chased and stabbed in Hackney, north London, on 1 May after denying being part of a local gang, the Old Bailey heard.
He died at the scene.
Two 15-year-old boys, who cannot be named because of their ages, are accused of his murder along with Romaine Williams-Reid, aged 18.
They all deny murder, wounding another boy with intent and possession of a knife.
A teacher, who worked at a school attended by one of the 15-year-olds, told jurors he was responsible for checking students with a metal detector as they arrived for lessons.
On 27 February, the defendant had moved towards student toilets and appeared to be trying to hide something before the teacher approached to scan him, jurors heard.
The teacher followed and asked to see what it was, to which the boy replied "nothing", the court heard.
The witness said: "I leant back to call for colleagues. I briefly looked away. As I looked back he was seen to be concealing something behind his trousers in his waistband.
"I hugged him as to get a better look as to what he was concealing."
He described seeing "a large Rambo-style knife in a sheath" which had a blade up to seven inches long.
"There was a very brief tussle between us both. I then immediately called assistance from my colleagues. Nobody answered," the court heard.
When asked to hand over the knife, the boy allegedly said: "No, I can't give it to you, it's not mine."
The teacher told him it was an illegal weapon and he would have no choice but to call the police.
The boy was later excluded from school for five days.
The trial continues.