One thing that I have found that the pomodoro technique trains in me is the muscle which works on exactly what you are concerned about. Initially I was concerned that when programming, I would be in the middle of a large refactor or stuck in the flow and then I would get bumped out of it by the end of the pomodoro coming and doing my rest interval.
After a couple of weeks programming using the pomodoros for focus, I found that it was much easier to remember where I was when I came back from a rest break. I understand that this is part of the technique, that you are also training yourself to be able to take short breaks without losing the place that you are at.
When I got about a month into using pomodoros for focusing on tasks, I've found that it not only helped just after a rest break, but also when I was coming back the next day or on a project which I had not worked on for a while. I would be able to remember my position even though I hadn't touched the project in a while. Part of it was that I knew that if I was done with my pomodoros for a day, I would leave a note or clean up quickly before quitting as well.