My trick is very simple and very low-tech. Take a piece of paper and a pen and draw a diagram that sums up the big picture of what you are trying to achieve (architecture of the software you’re writing for instance). Take as long as you need to, and when things start to fall naturally into place and you are eager to start, pick one part of the drawing and start working. Avoid distraction at all cost (music does help, especially in an open space).
I developed this when I was in academia and it transposed very well (better?) in the software industry. If you do that regularly it also helps course-correct when needed.