Characters and notification bounce when Terminal loses focus
Some program you're interacting with has enabled terminal Focus In/Out events, normally used along with Mouse Reporting (aka “Xterm Mouse Tracking”). When enabled, the terminal sends events to the TTY to indicate when the terminal gains or loses keyboard focus (i.e., becomes active or inactive).

The terminal command for enabling focus events is:

CSI ? 1 0 0 4 h


(CSI = Control Sequence Introducer: ESC [.)

The focus in/out events that the terminal sends to the tty are:

Focus In:  CSI I
Focus Out: CSI O


These are the sequences you're seeing when you use cat to view them.

The terminal Dock-icon bounce and badge indicate when a BEL (Control-G) is sent to the terminal when it isn't the active/frontmost terminal. (There are preferences to control these behaviors in Preferences > Profiles > [profile] > Advanced.)

So it appears that some program has enabled Focus In/Out events and is sending a BEL in response to them.

It could also be that the program sending the BEL is not the same as the program that enabled the Focus In/Out events. For example, an editor like vim may have enabled them, but some intervening program like screen or tmux (or possibly ssh, although it seems less likely) is intercepting the Focus In/Out events and responding with a BEL to indicate that it considers the input to be invalid.


  …it's happening in a tab running an SSH session…


Since you didn't say, I'll assume you're just using a shell within that session and not some other program. If that's the case, it's likely that you ran some preceding program within that SSH session that enabled the focus events and then exited without disabling them, leaving the shell to receive them, and if you type ESC [ I or ESC [ O manually into Bash, by default it will emit a BEL to indicate that the input is considered invalid.

If you have only used a shell within that SSH session, then you should examine the shell startup/configuration files on the remote host to see if there's some code to enable the focus events.

You can simulate this situation by running the following command in Bash (and probably other shells):

printf '\e[?1004h'


Then you'll find that Bash beeps (sends a BEL) when you activate or deactivate the terminal view/window.