As I am somebody that currently medicates with stimulants for their ADHD induced inattention, I still have a big bag of tricks to make me do stuff.
And there are many hacks - you limit the scope (Tiny Habbits by BJ Fogg is a masterclass on this, and Unfck your habitat by Rachel Hoffman falls here too)
I used to live by my work-playlist. I.e. Tron Legacy OST could give me more than an hour of uninterupted focus!
Having another person can be helpful as well - doesn't matter if oyu work from home with partner or friend, go back to the office, to the library or stream your workflow - I sometimes make one where I am the only person in the meeting, but just the possibility that somebody joins while I am sharing my screen keeps me productive.
I assume that pair-programming can similarily help.
Having good break rituals as well - "Going to get coffee/soda" is well defined and I can return back.
Having nice actual work environment where I don't need to remember too much and the feedback loop is tight. I am doing much of my prototiping in shell or in notebook environment, where answer to "so what will this actually do" is usually single key-stroke away.
In the end you will need to figure this out. Some people live by library-rules and quiet. Other work better with people and abient conversation. Sometimes you will have a specific project that works in a way that just clicks and you won't need so many productivity hacks.