I’d be willing to bet they agreed on how to do it before they did it. Almost certainly stagecraft.
And Barr got to declare his independence and tell Trump to knock it off [which he isn't going to do if he sees a need to do it].
And the press made sure we all know about this little skit.
Brilliant.
All the world's a stage, and all the men and women merely players: they have their exits and their entrances; and one man in his time plays many parts, his acts being seven ages.