I'd pick up my phone for five minutes and look up an hour later. By the end of the day, I couldn't tell how much time I'd actually spent coding.
To focus while coding, choose one task, start a 25 minute block on it, keep your phone and your feeds out of reach until it ends, and count the blocks you finish. Start with one block and see where you get pulled away.
Find where your time goes
"I get distracted" is too vague to fix. Mine has names. Facebook. Twitter. A post on LinkedIn that makes me think of something else I should be doing. I open one of them and lose my sense of time.
Coding gives you plenty of openings for it, because it is full of small waits:
- The build or the tests are running.
- You are waiting for a review, or for an AI assistant to finish.
- You are stuck, and the next step is not clear.
Try this
For one day, write down the app you opened each time you drifted, and what you were doing just before. Change nothing else yet.
Pick one task first
Before you start the timer, name the first thing you'll do.
Make the task small enough that you know the first move:
- Too big:
work on login - Better:
reproduce the login redirect bug locally
If you cannot name the first move, finding it is the task. Give that a block of its own.
Start one 25 minute block
I use 25 minutes of work and 5 minutes of break. Pick the task, press start, begin. The length matters less than the fact that it ends. I do not have to promise myself a whole focused afternoon. I only have to leave the phone alone until the timer ends, and then I get a break.
Some work needs longer. If the timer keeps stopping you just as the problem is loaded in your head, try 50 minutes. If you drift before it ends, go shorter. Read Pomodoro for programmers for help choosing a length, or try a block with the free focus timer.
Make the feed harder to reach
You check what is close. Before you press start, put some distance between you and the things you listed in step 1:
- Leave the phone in another room, or at least out of arm's reach and face down.
- Close the social tabs. A pinned tab with an unread count is an invitation.
- Keep open only the tabs this task needs.
- Silence chat until the block ends. If you are on call, let only those alerts through.
If you need a site for work, like LinkedIn for a message, make it a task and give it its own block. Then it has a start and an end like everything else.
Catch the switch
For me, focus usually breaks at a switch. I change tabs or tasks, I see something, and my mind moves to that. It does not feel like a distraction when it happens. It often looks like work: another bug, an idea, a message I should answer.
There is research behind this. In two experiments, Sophie Leroy found that people had difficulty moving their attention away from an unfinished task, and did worse on the next one. She calls it attention residue (Leroy, 2009). More on this in context switching for developers.
- Notice it. You are in a tab this task does not need.
- Write one line about the new thing, so you can let go of it.
- Go back to the line of code you were on.
While a build or a test run goes, stay with the same task. Read the diff, write the next test, or just wait. The wait is usually shorter than the feed.
Count the blocks
Before, I didn't track my day. Now I can see how much time I spent in focus blocks.
A mark on paper for each finished block is enough. At the end of the day, look at the number. Do not turn it into a score or compare it with anyone. It answers one question: did today go where I thought it went?
When the day is already gone
Some days you look up and it is four in the afternoon. Do not try to win back the whole day. Do one block:
- Lost an hour?
- Put the phone away, pick the smallest task you have, and start 25 minutes.
- Stuck?
- Write what you tried and what you expected. Ask someone, or make the next step smaller.
- Tired?
- Take a real break away from every screen. A feed is not a rest.
One finished block is a better end to a bad day than a plan to do better tomorrow.
Doing this with Ippo

You can do this with a kitchen timer and paper. I used to start my music by hand, and my tasks never stayed in sync across my tools. That's why I built Ippo. I pick a task and press Space to start the timer, and my music can start with it. Ippo saves each finished block on its task so I can see what I worked on at the end of the day.