That moment when you think about a smarter reply that you could've given? [duplicate]

The phrase you are looking for may be l'esprit de l'escalier, or staircase wit. Both the original French and the English translation are used in English.

The phrase comes from thinking of the perfect reply to somebody at the bottom of the stairs, just when you are leaving their house, when it is too late to use it.