The expression “keep it under your hat” generally means to keep something a secret. There are a few theories as to the phrase’s origin, of which only one makes any real sense. In a mid-nineteenth century novel, William Thackeray wrote:”…a distinct universe walks about under your hat and under mine…” . He was referring, of course, to our minds. So “keep it under your hat” basically meant keep it in your head. You may know it, but don’t say it.
There is also another early reference to the exact phrase, which I was able to find while mulling about the catacombs of the famous Jollygood Library in London. Amidst the dusty tomes I discovered a diary of the butler of the Earl of Earl. In an entry dated October 9, 1903, he references an encounter with the Earl’s cousin, the Duke of Earl, as the Duke arrived for brunch. The butler notes that as the Duke doffed his hat, he appeared to have a dead squirrel on top of his head. Discreet as he tried to be, the butler could not avert his gaze from the bulging rodent eyes staring at him. The Duke noticed, of course.
Duke: I see you are a man of keen observation skills. Truth be told, my regular hairpiece needed to be cleaned, and its backup was nowhere to be found. So I had my man obtain this makeshift replacement. I assure you the animal was fed before being bludgeoned, lest you think me a barbarian.
Butler: Not at all, sir. But might I suggest that you keep it under your hat.
It is quite likely that this is the first actual use of the phrase. Or perhaps not.