If you accept that the whole job isn't just interacting with your IDE, then you stop thinking stuff like "Oh no, who's looking at my screen now? Who's gonna find out that I'm on HN?"
My solution is simply practice - making a planned, conscious effort to get back to my work whenever I'm distracted. At first, I could lose up to half an hour distracted before realizing that I'm distracted and go back to work. But after a while, the time-to-realize got smaller and smaller. Once you get to a small enough interrupt window, it'e effectively the same as not being interrupted at all.
You can stop an intrusive thought from entering your mind just by realizing that it would harm your focus? Is it possible to learn this power?