Long tasks with an AI coding agent: how not to lose the thread
The longer the conversation, the worse the agent holds the task: it forgets your rules and repeats mistakes you already fixed. Long work needs a clean context and a Mac that does not fall asleep.
Why the agent gets worse toward the end
Every model has a context window: how much text it holds at once. The conversation, the files it read, command output all pile up there. As the window fills, trouble starts:
- a rule you gave at the start drowns among thousands of log lines;
- the agent proposes again the fix you already rejected;
- Claude Code and Codex compact the context on their own, and details get lost in compaction.
Compaction is not a bug, but you do not control what survives it. It is safer to decide yourself when to start fresh, and to tell the agent yourself what to carry over.
Refresh the session in time
A good rule: do not run the window to the edge. Start fresh when a stage is done, not when the agent is already confused.
In Hedoq that is one button, “Refresh session”:
- Under the input field, the context line shows how much of the window is used.
- At 70 % and 90 %, a hint appears above the field.
- After you confirm, the agent writes a note for its successor: the project and where it lives, your rules and bans from this conversation, what is done, where it stopped, what is next, which files to read.
- The context is cleared. The new conversation gets the note, reads the files and answers briefly: what we are doing, where we are, what is next.
If the note was not saved, the context is not cleared, so you cannot lose work this way. The old conversation stays in the feed above a line. It works for Claude Code and Codex, and the button is on the iPhone too. When Claude Code compacts the context itself, the feed shows a line about it: how many tokens before and after.
Let the Mac work with the lid closed
A task that takes hours often outlives the trip home. You close the laptop, macOS puts it to sleep, the agent stops halfway.
In Hedoq, turn on “Stay awake with the lid closed”. The switch is in the settings and at the bottom of the notch by the camera.
- The first time, it asks for an administrator password: Hedoq installs a system rule for this mode only.
- While the mode is on, the Mac does not sleep with the lid closed; the screen goes dark and the sound is muted.
- Below 20 % battery the rule is lifted and the Mac sleeps.
- If Hedoq quits, the rule is removed on its own.
The mode keeps the Mac awake the whole time it is on, not only during agent turns. That way the phone keeps its link between turns too, and you can answer the agent from your iPhone while the laptop is in your bag. How: agents from your phone.
Hand repeating work to an automation
Part of the long work actually repeats: build a report every morning, check a site every hour. There is no need to keep a session open for that.
In Hedoq the agent builds the automation itself:
- In the sidebar, under Automations, press “New task” (⌘⇧N).
- Describe in words what is needed and when.
- The agent asks one question if something is missing, picks how to run it, puts everything into the automation folder and turns the schedule on. You confirm that in a window on the Mac or the iPhone.
The automation card shows the state: “Runs smoothly”, running, stopped, or “Errors: N”. The agent leaves a description and a log of what was done in the folder, so the next agent can carry on without you.
For a one-off task from a regular session there is the ⚡ command “Run on a schedule”: the agent shows the name, time and task text and sets it up after your “yes”.
A watchdog instead of checking by eye
An automation that silently broke a week ago is worse than none. So in Hedoq a watchdog follows every run. It is an algorithm, not a model: it judges by facts.
- A run ended with an error, or runs much longer than usual: that is an error.
- A new error goes to the automation’s agent with a request to fix it. One attempt per series of errors.
- If that does not help: a notification on the Mac and on the phone.
- If the agent is unavailable (not installed, or its limit is used up), the next installed agent takes over, in the order Claude, Codex, Gemini, OpenCode. The work is handed over through files in the folder, and the original agent comes back later.
For scheduled tasks, “done” means one thing: the turn ended by itself and without an error. A task that did not start, waits for an action on screen or runs longer than two hours counts as a failure.
One condition for all of this: Hedoq has to be open and the Mac awake. With the lid-closed mode, that takes care of itself.