Under the hat.

This idiom or expression means:

Secret.

When someone says “Keep it under your hat,” they mean something like:

Do it quietly.
Keep it a secret.
Keep it to yourself.
Don’t tell anybody about it. Etc.