When someone tells you something and then follows it up by saying, “keep it under your hat” what he wants you to do is to keep the information to yourself. The information is to be kept secret; if the secret stays under your hat, it stays in your mind.
*I have some interesting news. I’ll tell you, if you promise to keep it under your hat. *Raju has been fired. But keep it under your hat.
In the old days in Britain, both boys and men used to wear hats. Some of the hats had secret compartments in them. Whenever a man carried something important, he invariably hid it in them. For example, when a man wanted to send a letter to his beloved, he hired a small boy from the streets. The boy was given the letter and it was his job to give it to the girl without her parents being aware of it. In order to ensure that he didn’t lose the letter and was in a position to give it to the girl without her parents finding out, the boy used to hide it under his hat!