You reach flow with AI by treating the agent as a junior engineer you trust in small windows, not a slot machine. Sophie Leroy's attention-residue research, which Cal Newport made famous in Deep Work, explains why every prompt-wait-judge loop fragments focus. Pick a 90-minute block, write the spec yourself first, then let Claude Code or Codex execute while you stay in the architecture.
Re-checked October 2026: three things on this page were wrong or have moved. The Stanford CS336 agent guidelines I cited do not tell students to run agents autonomously; they tell AI assistants to act as tutors that explain, ask guiding questions and review, and not to write, run or edit the students’ code. The twenty-minute figure I attributed to Newport is not in the research: Sophie Leroy’s 2009 experiments show that residue from unfinished work hurts performance on the next task, with no universal number of minutes attached. And Forge’s README now reports an 8B local model going from single digits to 84% on its harder 26-scenario v0.7.0 suite, rather than the 53% to 99% of its May 2026 launch post. The method below is unchanged.
The Hacker News thread that prompted this question — “How do you get into a flow state when using AI to code?” — was posted on June 11, 2026, drew 98 points and about seventy top-level replies, and the comments revealed the same split I see in my own week. Half of the working engineers said AI agents finally gave them the deepest flow of their careers; the other half said the constant prompt-judge-redirect loop killed every focus session they tried to start. Both groups are telling the truth. The difference is structural, not personal, and it lines up almost perfectly with what Cal Newport, building on the organizational psychologist Sophie Leroy, calls attention residue in Deep Work.
Here is the mechanism. Flow, in Mihaly Csikszentmihalyi’s original definition, requires a stable challenge-skill ratio, a clear goal, immediate feedback, and — critically — uninterrupted absorption. The way most developers use Cursor, Claude Code, or GitHub Copilot in 2026 violates the last condition systematically. You type half a thought, hit tab, judge the suggestion, accept or reject, retype, prompt again, watch a 40-second agent run, scan a diff, approve, repeat. Leroy found that when you leave a task unfinished, part of your attention stays behind with it and your performance on the next task drops. Every agent run you abandon mid-judgment is an unfinished task, and AI coding tools serve up one every few seconds. No wonder people surface from a four-hour session feeling like they sprinted nowhere.
What I do — and what most of the engineers in that HN thread who reported genuine flow described — is the opposite of conversational, turn-by-turn prompting. I write the spec myself, in plain text, before I open the agent. Not a vibe, not a sentence. Three to ten lines of: here is the function signature, here is the failing test, here is the constraint, here is the file structure. Then I hand the whole thing to Claude Code or Codex in one shot and walk away from the screen until it finishes. While it runs, I read the next requirement on paper. When it returns, I judge the diff as a code review, not as a conversation. That collapses the loop from twenty micro-decisions to two or three macro-decisions per block — and that is exactly the shape Newport prescribes.
The Stanford CS336 AI agent guidelines that reached the Hacker News front page on June 1, 2026 come at the same problem from the other side: they tell coding assistants to explain, ask guiding questions and review, and not to write, run or edit the students’ code, because the learning happens in the part of the work the human does. That is the same split I am describing, applied to students: the human keeps the thinking, the tool stays out of it. The Show HN game Continue? Y/N, a sixty-second simulation of agent permission fatigue posted on May 28, 2026, turned the cost of constant approvals into a joke. It is not a joke. The Forge project, a Show HN on May 19, 2026, makes the engineering version of the point: deterministic guardrails such as output validation, retry nudges and required steps took an 8-billion-parameter model from 53% to 99% on its launch benchmark, and its current README reports single digits to 84% on a harder 26-scenario suite, so the human stops having to babysit every step.
The honest part: this only works if the spec is good. I have wasted entire mornings handing a half-formed prompt to an agent, watching it produce a confident wrong answer, and then trying to debug my way to clarity through more prompting. That is not flow. That is gambling. Naval Ravikant’s line about judgment over hard work applies directly to AI-assisted coding — the leverage is enormous, but the leverage multiplies whatever judgment you put in. If your judgment about what to build is fuzzy, the agent will amplify the fuzziness at machine speed.
So my actual rule is sequential. First block of the morning: no AI. Pen, notebook, or markdown buffer. Write the problem, the constraints, the success criteria. This is the architecture phase, and it is irreducibly human because the agent cannot help you decide what the right thing to build is. Second block: AI-augmented execution. Hand the spec to the agent, let it run, review the diff, ship. Phone in another room, Slack closed, agent in autonomous mode with a long timeout. Third block, after lunch: integration and tests, which I do mostly by hand because that is where I learn what the agent missed.
The engineers I know who hate coding with AI are almost all stuck in the conversational mode — chatting with the model, accepting completions one at a time, never leaving the loop. The engineers who love it have, almost without exception, separated the two phases. Ethan Mollick in Co-Intelligence calls this the “jagged frontier” — knowing where the AI is super-human and where it is sub-human, and structuring your work so you stay on the human side of the jag during the parts that matter. Flow, it turns out, is a planning problem. Treat the agent as a junior engineer you trust for ninety minutes at a time, and the flow comes back.
Sources: Hacker News, “Ask HN: How do you get into a flow state when using AI to code?” June 11, 2026 (https://news.ycombinator.com/item?id=48492118); Stanford CS336, AGENTS.md AI agent guidelines (https://github.com/stanford-cs336/assignment1-basics/blob/main/AGENTS.md) and the Hacker News discussion of June 1, 2026 (https://news.ycombinator.com/item?id=48359232); Show HN, “Continue? Y/N: A 60-second game about AI agent permission fatigue,” May 28, 2026 (https://news.ycombinator.com/item?id=48308376); Forge README, reviewed October 15, 2026 (https://github.com/antoinezambelli/forge) and its Show HN of May 19, 2026 (https://news.ycombinator.com/item?id=48192383); summary of Sophie Leroy (2009) and Leroy & Glomb (2018) on attention residue (https://www.brnsft.com/blog/attention-residue-sophie-leroy-context-switching); Cal Newport, Deep Work (2016); Ethan Mollick, Co-Intelligence (2024).
Related: How to Find Your Passion · Best Self-Improvement Books · How to Make Better Decisions · AI Coach App — Building It in 8 Hours
