How do you deal with this?
Either moving for a while or resting (depending on how you feel), even taking a quick ("alarmed") nap if you're lucky enough to be allowed to do it, is actually a very good idea, in all likelihood; you might think that that would mean losing your focus but you'll get back to it much quicker (often instantaneously), and probably even a little refreshed, if you don't start another activity.
It's only tangentially related, but if you're worried about focus you should probably give a try to the Pomodoro technique, if you never heard of it before.
And if you can postpone some "intermitting" activity, and maybe group a batch of them half-an-hour from now and now instead carry on your coding or whatever you're focused on for a little longer, it's probably beneficial