<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Will Gwyn</title>
    <description>The latest articles on DEV Community by Will Gwyn (@wrg32786).</description>
    <link>https://dev.to/wrg32786</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4180242%2Fe9b1126b-5798-409a-9e5e-f00672fff25e.jpg</url>
      <title>DEV Community: Will Gwyn</title>
      <link>https://dev.to/wrg32786</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/wrg32786"/>
    <language>en</language>
    <item>
      <title>How to keep a Claude Code agent running for days without losing context</title>
      <dc:creator>Will Gwyn</dc:creator>
      <pubDate>Fri, 16 Oct 2026 19:18:59 +0000</pubDate>
      <link>https://dev.to/wrg32786/how-to-keep-a-claude-code-agent-running-for-days-without-losing-context-520b</link>
      <guid>https://dev.to/wrg32786/how-to-keep-a-claude-code-agent-running-for-days-without-losing-context-520b</guid>
      <description>&lt;p&gt;You don't keep one context window alive for days. You run a chain of bounded sessions that share durable state on disk (a progress file, a task list, git history), and you make the handoff between sessions automatic and checkable.&lt;/p&gt;

&lt;p&gt;I've been running Claude Code agents this way for months, and most of what goes wrong happens at the boundary between sessions, not inside them. So this is mostly about that boundary.&lt;/p&gt;

&lt;h4&gt;
  
  
  What Claude Code gives you on its own
&lt;/h4&gt;

&lt;p&gt;A single session doesn't last forever because the context window fills. When it does, Claude Code compacts automatically, summarizing the history so the session can continue. Anthropic's docs list what survives that: project-root CLAUDE.md, unscoped rules and auto memory get re-injected from disk, and a handful of recently touched files get re-read. Everything else becomes part of a summary. Auto memory, which the docs describe as notes Claude writes itself based on your corrections and preferences, also carries across sessions.&lt;/p&gt;

&lt;p&gt;Between sessions you have &lt;code&gt;/clear&lt;/code&gt; to start fresh, &lt;code&gt;/resume&lt;/code&gt; to return to an earlier conversation, and subagents to do heavy reading in their own context so your main window stays lean. There's also a built-in &lt;code&gt;/goal&lt;/code&gt; command. Per the command reference, it keeps Claude working across turns until a condition you set is met. As far as I can tell from the docs, it's about finishing a task, not carrying memory from one window to the next.&lt;/p&gt;

&lt;h4&gt;
  
  
  What Anthropic recommends for long-running work
&lt;/h4&gt;

&lt;p&gt;The clearest guidance is Anthropic's engineering post "Effective harnesses for long-running agents." Its framing stuck with me: agents "must work in discrete sessions, and each new session begins with no memory of what came before." Their answer was an initializer session that sets up an &lt;code&gt;init.sh&lt;/code&gt;, a &lt;code&gt;claude-progress.txt&lt;/code&gt; log and an initial git commit. After that, every session makes incremental progress on one feature, commits with a descriptive message and updates the progress file. The next session starts by reading that file and the git log.&lt;/p&gt;

&lt;p&gt;Anthropic also published a companion repo, anthropics/cwc-long-running-agents, that turns those patterns into small hooks. It includes a structured &lt;code&gt;PROGRESS.md&lt;/code&gt;, a commit-on-stop hook as a backstop, and a separate evaluator agent that grades the work from a fresh context.&lt;/p&gt;

&lt;p&gt;Community advice lands in the same place. The most useful Reddit thread I found on running agents "for weeks" argued for treating each model session as a replaceable worker and keeping the real state (task graph, decisions, next action) outside it. A second tip from the same threads: have subagents write their output to disk and hand back a path and a one-line summary, so the orchestrator doesn't fill up with their raw output.&lt;/p&gt;

&lt;h4&gt;
  
  
  The options, honestly
&lt;/h4&gt;

&lt;p&gt;You can do all of this by hand with CLAUDE.md, a progress file and git, and for many projects that's enough. If you want help, several tools cover different parts. claude-mem captures what your agent does, compresses it and injects relevant context into future sessions. context-mode keeps tool output from flooding the window and persists session memory. claude-auto-handoff replaces auto-compact with a structured brief, a &lt;code&gt;/clear&lt;/code&gt; and a seeded fresh session. Hindsight is a memory service built to learn across agents. They overlap, and plenty of people run two together.&lt;/p&gt;

&lt;h4&gt;
  
  
  What I run (I built this)
&lt;/h4&gt;

&lt;p&gt;I built aigent-OS, so read this as the author talking. It's an open-source Claude Code harness that refreshes its own context instead of compacting. At a context threshold (80% by default) it asks Claude to write a capsule, waits for one exact acknowledgement, sends a single &lt;code&gt;/clear&lt;/code&gt;, confirms via the &lt;code&gt;SessionStart&lt;/code&gt; hook that a new session really started, and resumes from the capsule. Memory is plain markdown in git. It's MIT licensed, runs locally and needs Node 18+: &lt;a href="https://github.com/wrg32786/aigent-os" rel="noopener noreferrer"&gt;https://github.com/wrg32786/aigent-os&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Running it for days taught me where the boundary breaks. Four aigent-OS seats run my newsletter, The AIgent. That's operating experience, not a measured result, and I'm not claiming it grew anything. In August a check of those four seats found that three would have resumed into a checkpoint with no actionable content. Now the capsule selector refuses that kind of checkpoint, and a test in the repo defends the fix. Stale notes were another problem, so notes can carry a validity window and rank below current ones once it ends. Memory that tries to give instructions gets held before it's saved, and saved memory is read back as data, never as commands.&lt;/p&gt;

&lt;p&gt;The limits are real. Managed Auto-Refresh is in the v1.1.0-rc.1 release candidate. The only formal public result is 11 of 11 clean refresh cycles on one seat. That's single-machine evidence, not proof at fleet scale. On rc.1, a long session can also stall at the clear step and need a manual &lt;code&gt;/clear&lt;/code&gt;. The fixes are merged on master and land in the next release. Two narrower acknowledgement bugs are still open as #90 and #91, so if you ever clear by hand, make sure the latest capsule is saved first.&lt;/p&gt;

&lt;h4&gt;
  
  
  FAQ
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Can a single Claude Code session literally run for days?&lt;/strong&gt;&lt;br&gt;
I didn't find a documented wall-clock limit on an interactive session, but the context window fills well before that. In practice, "days" means compactions or clear-and-resume cycles.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What should the progress file contain?&lt;/strong&gt;&lt;br&gt;
Anthropic's post uses what was done, what's next and known issues, backed by git commits. I'd add the exact next step. A checkpoint without one is the failure I hit most.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Do subagents help?&lt;/strong&gt;&lt;br&gt;
Yes, for big reads and searches, as long as they return a short result and a file path instead of everything they saw.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Is compaction good enough for long runs?&lt;/strong&gt;&lt;br&gt;
Often, especially if your durable state lives in files. Compaction loses detail, so anything you can't afford to lose belongs on disk.&lt;/p&gt;

</description>
      <category>claudecode</category>
      <category>ai</category>
      <category>agents</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Claude Code /compact vs /clear: what actually happens to your context</title>
      <dc:creator>Will Gwyn</dc:creator>
      <pubDate>Fri, 16 Oct 2026 19:17:58 +0000</pubDate>
      <link>https://dev.to/wrg32786/claude-code-compact-vs-clear-what-actually-happens-to-your-context-55d8</link>
      <guid>https://dev.to/wrg32786/claude-code-compact-vs-clear-what-actually-happens-to-your-context-55d8</guid>
      <description>&lt;p&gt;&lt;code&gt;/compact&lt;/code&gt; replaces your conversation with a summary Claude writes and keeps the same session going. &lt;code&gt;/clear&lt;/code&gt; starts a new conversation with an empty context. Your project memory, like CLAUDE.md, still loads, and the old conversation stays available through &lt;code&gt;/resume&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;That's the short version. The longer version matters, because the two commands look alike in the prompt bar and behave very differently, and I've watched people (me included) pick the wrong one mid-task and lose a decision that took an hour to reach.&lt;/p&gt;

&lt;h4&gt;
  
  
  What /compact does
&lt;/h4&gt;

&lt;p&gt;Anthropic's command reference describes &lt;code&gt;/compact [instructions]&lt;/code&gt; as freeing up context "by summarizing the conversation so far," with optional focus instructions. Run &lt;code&gt;/compact focus on the API changes&lt;/code&gt; and the summary leans toward what you named. You can also compact part of a conversation from &lt;code&gt;/rewind&lt;/code&gt; with "Summarize from here" or "Summarize up to here." The automatic pass Claude Code runs near the limit is the same operation. You just don't get to steer it.&lt;/p&gt;

&lt;p&gt;After a compaction, the docs list what comes back on its own. The system prompt and output style still apply. Project-root CLAUDE.md, unscoped rules and auto memory get re-injected from disk. Up to five recently modified files Claude touched get re-read, and a file over 5,000 tokens comes back only as a path. Invoked skills return within a per-skill cap. The rest of the conversation, including path-scoped rules, nested CLAUDE.md files and context that hooks added, lives on only as whatever the summary kept.&lt;/p&gt;

&lt;p&gt;There's a cost detail people miss. The costs page notes that &lt;code&gt;/compact&lt;/code&gt; "reads the conversation it summarizes, so compacting a large context is itself a large request."&lt;/p&gt;

&lt;h4&gt;
  
  
  What /clear does
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;/clear&lt;/code&gt; (aliases &lt;code&gt;/reset&lt;/code&gt; and &lt;code&gt;/new&lt;/code&gt;) starts a new conversation with empty context. The commands overview says it "starts fresh on a new task while keeping project memory," so CLAUDE.md and auto memory load as usual in the new session. The same costs page says that when you want a fresh start instead of continuity, "/clear costs nothing."&lt;/p&gt;

&lt;p&gt;The question I get most is whether &lt;code&gt;/clear&lt;/code&gt; is permanent. Anthropic's sources don't quite agree here. The help center article on models and limits warns that &lt;code&gt;/clear&lt;/code&gt; can't be undone. The command reference says you can return to the previous conversation with &lt;code&gt;/resume&lt;/code&gt;, and that in the same Claude Code process the rewind menu shows a "previous session" entry. My reading: the old transcript is still there to go back to, but nothing from it carries into the new session unless you bring it. If something matters, write it down first.&lt;/p&gt;

&lt;h4&gt;
  
  
  How to tell which one happened
&lt;/h4&gt;

&lt;p&gt;If you write hooks, the two commands are easy to tell apart. &lt;code&gt;SessionStart&lt;/code&gt; fires with &lt;code&gt;source&lt;/code&gt; set to &lt;code&gt;compact&lt;/code&gt; after a compaction and &lt;code&gt;clear&lt;/code&gt; after &lt;code&gt;/clear&lt;/code&gt;, and &lt;code&gt;PreCompact&lt;/code&gt; fires first with a &lt;code&gt;manual&lt;/code&gt; or &lt;code&gt;auto&lt;/code&gt; trigger. That's how tools that manage context, mine included, know which boundary they just crossed.&lt;/p&gt;

&lt;h4&gt;
  
  
  Which one should you use?
&lt;/h4&gt;

&lt;p&gt;Anthropic's own session management guide on claude.com gives the trade-off better than I can. Compaction is "lossy, but you didn't have to write anything yourself." With &lt;code&gt;/clear&lt;/code&gt; you write down what matters and start clean, which is more work, but "the resulting context is what you decided was relevant." Their rule of thumb is &lt;code&gt;/compact&lt;/code&gt; when you're mid-task and the session is bloated, and &lt;code&gt;/clear&lt;/code&gt; when you're starting something new.&lt;/p&gt;

&lt;p&gt;That leaves a gap for long tasks where you want both: a clean window, plus the decisions from the last two hours. That's where most of the community tooling lives. Some people do it by hand: ask for a handoff note, &lt;code&gt;/clear&lt;/code&gt;, paste it back. claude-auto-handoff automates that by having Haiku write the brief before running &lt;code&gt;/clear&lt;/code&gt;. claude-mem works from the memory side, capturing what your agent did and injecting relevant context into later sessions, so a fresh window starts less empty. context-mode reduces how much tool output lands in your context in the first place, which means you hit either command less often.&lt;/p&gt;

&lt;h4&gt;
  
  
  Where aigent-OS fits (I built this)
&lt;/h4&gt;

&lt;p&gt;I built aigent-OS, so take this as the author's description. It automates the clean-window path. At a context threshold (80% by default) it asks Claude to write a capsule, a checkpoint file with the work state and next step. It waits for one exact acknowledgement, sends a single &lt;code&gt;/clear&lt;/code&gt;, confirms through &lt;code&gt;SessionStart&lt;/code&gt; that a new session really started, and resumes from the capsule. If the acknowledgement never comes, it never clears. Memory is plain markdown in git, so you can diff what the agent remembers. It's MIT licensed, runs locally and needs Node 18+: &lt;a href="https://github.com/wrg32786/aigent-os" rel="noopener noreferrer"&gt;https://github.com/wrg32786/aigent-os&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The honest status: Managed Auto-Refresh is in the v1.1.0-rc.1 release candidate. The public evidence is 11 of 11 clean cycles on one machine. On rc.1 a long session can still stall at the clear step and need a manual &lt;code&gt;/clear&lt;/code&gt;. The fixes are merged on master and ship in the next release, and two smaller acknowledgement edge cases (#90 and #91) are still open. I don't claim it's better than compaction. It trades a model-written summary for a checkpoint you can open and read.&lt;/p&gt;

&lt;h4&gt;
  
  
  FAQ
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Does /clear delete my CLAUDE.md or project files?&lt;/strong&gt;&lt;br&gt;
No. It clears the conversation. Project memory loads again in the new session, and your files aren't touched.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Can I get back to a conversation after /clear?&lt;/strong&gt;&lt;br&gt;
According to the command reference, yes, through &lt;code&gt;/resume&lt;/code&gt; or the rewind menu's previous-session entry in the same process.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Which is cheaper?&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;/clear&lt;/code&gt;. Compacting has to read the whole conversation to summarize it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Does /compact keep my files in context?&lt;/strong&gt;&lt;br&gt;
It re-reads up to five recently modified files Claude worked on. Larger ones come back as a path reference only.&lt;/p&gt;

</description>
      <category>claudecode</category>
      <category>ai</category>
      <category>devtools</category>
      <category>productivity</category>
    </item>
    <item>
      <title>How do I stop Claude Code from auto-compacting (and losing context)?</title>
      <dc:creator>Will Gwyn</dc:creator>
      <pubDate>Fri, 16 Oct 2026 19:15:40 +0000</pubDate>
      <link>https://dev.to/wrg32786/how-do-i-stop-claude-code-from-auto-compacting-and-losing-context-278l</link>
      <guid>https://dev.to/wrg32786/how-do-i-stop-claude-code-from-auto-compacting-and-losing-context-278l</guid>
      <description>&lt;p&gt;Turn off auto-compact in &lt;code&gt;/config&lt;/code&gt; (the Auto-compact toggle), or set &lt;code&gt;"autoCompactEnabled": false&lt;/code&gt; in your settings file, or launch with &lt;code&gt;DISABLE_AUTO_COMPACT=1&lt;/code&gt;. That stops the automatic summary, but it doesn't give you a bigger context window, so you still need a plan for the moment the window fills.&lt;/p&gt;

&lt;p&gt;I keep seeing this question on r/ClaudeCode and in Claude Code's GitHub issues, usually right after someone loses an afternoon of decisions to a summary. So here's what Claude Code actually does, what the switches change, and the ways people deal with it, mine included.&lt;/p&gt;

&lt;h4&gt;
  
  
  What Claude Code does by default
&lt;/h4&gt;

&lt;p&gt;Claude Code compacts on its own as you approach the context limit. Anthropic's context window docs put it plainly: "Claude Code compacts automatically as you approach the limit, so a full context window doesn't end your session." Compaction replaces the conversation history with a model-written summary and you keep going on top of that summary.&lt;/p&gt;

&lt;p&gt;Where it triggers depends on the model. The model configuration page says models with a native 1M window compact at about 967K tokens by default, and some setups, like Sonnet 4.6 and Opus 4.6 without extended context, compact at the 200K boundary. You can check yours with &lt;code&gt;/context&lt;/code&gt;, which shows what's filling the window.&lt;/p&gt;

&lt;p&gt;The part that matters most is what survives. The docs have a table for it. The system prompt still applies. Project-root CLAUDE.md, unscoped rules and auto memory get re-injected from disk. Claude Code re-reads up to five of the files Claude touched, most recently modified first. Invoked skills come back, capped at 5,000 tokens each. Path-scoped rules, nested CLAUDE.md files and anything a hook added earlier get summarized along with everything else. And anything you only ever said in chat is at the mercy of the summary. The memory docs say the same thing from the other side: if an instruction vanished after compaction, it probably lived only in the conversation.&lt;/p&gt;

&lt;h4&gt;
  
  
  The switches
&lt;/h4&gt;

&lt;p&gt;Anthropic documents several. &lt;code&gt;autoCompactEnabled&lt;/code&gt; (default &lt;code&gt;true&lt;/code&gt;) turns automatic compaction off, and &lt;code&gt;/config&lt;/code&gt; writes that key for you. &lt;code&gt;DISABLE_AUTO_COMPACT=1&lt;/code&gt; does the same for a session. In both cases manual &lt;code&gt;/compact&lt;/code&gt; still works. &lt;code&gt;DISABLE_COMPACT=1&lt;/code&gt; goes further and disables manual &lt;code&gt;/compact&lt;/code&gt; too. If you only want compaction to happen earlier, &lt;code&gt;/autocompact 500k&lt;/code&gt; or the &lt;code&gt;autoCompactWindow&lt;/code&gt; setting moves the trigger. &lt;code&gt;CLAUDE_AUTOCOMPACT_PCT_OVERRIDE&lt;/code&gt; can only lower the threshold, never raise it.&lt;/p&gt;

&lt;p&gt;There's also a hook-level option. The hooks reference says a &lt;code&gt;PreCompact&lt;/code&gt; hook can block compaction by exiting with code 2. If the compaction was proactive, the session continues uncompacted. If it was recovering from a context-limit error the API already returned, the error surfaces instead.&lt;/p&gt;

&lt;p&gt;One caution. In a long GitHub issue (anthropics/claude-code #42817), a user reports compaction firing even with the setting off. I couldn't reproduce that or confirm it either way, so if this matters to you, test it on your version.&lt;/p&gt;

&lt;h4&gt;
  
  
  So what do you do instead?
&lt;/h4&gt;

&lt;p&gt;The simplest fix is to leave compaction on and steer it. Put rules that have to survive in the project-root CLAUDE.md, add a "Compact Instructions" section there, and run &lt;code&gt;/compact focus on the auth refactor&lt;/code&gt; yourself before the automatic pass picks for you. That's free and it's built in.&lt;/p&gt;

&lt;p&gt;The most common workaround I see is a manual handoff. People turn auto-compact off, watch the status line, and somewhere around 70 to 75 percent ask Claude to write a handoff document, then &lt;code&gt;/clear&lt;/code&gt; and tell the new session to read it. It works well. Its cost is your attention, and it fails exactly when you're deep in the work and forget.&lt;/p&gt;

&lt;p&gt;Then there are tools that automate parts of this. claude-auto-handoff (alexknowshtml on GitHub) does the handoff for you: before the window fills it has Haiku write a structured brief, runs &lt;code&gt;/clear&lt;/code&gt;, and seeds the fresh session with one line telling it to read the brief. claude-mem takes a different angle: it captures what your agent does, compresses it, and injects relevant context into later sessions. context-mode attacks the input side by sandboxing tool output so less of it lands in your window, and it persists session memory too. Using subagents for big reads helps for the same reason. These overlap, and you can run more than one.&lt;/p&gt;

&lt;h4&gt;
  
  
  Where aigent-OS fits (I built this)
&lt;/h4&gt;

&lt;p&gt;Disclosure first: I built aigent-OS, so weigh this paragraph accordingly. It's an open-source Claude Code harness that refreshes its own context instead of compacting. At a threshold, 80% by default, it asks Claude to write a checkpoint I call a capsule. It waits for one exact acknowledgement, sends a single &lt;code&gt;/clear&lt;/code&gt;, confirms through the &lt;code&gt;SessionStart&lt;/code&gt; hook that a genuinely new session started, then resumes from the capsule. No acknowledgement, no clear. Memory is plain markdown in git, so you can read what it remembers with &lt;code&gt;git log&lt;/code&gt;. It's MIT licensed, runs locally and needs Node 18+.&lt;/p&gt;

&lt;p&gt;Here's what I can and can't tell you about it. Managed Auto-Refresh is in a release candidate, v1.1.0-rc.1. The public evidence is 11 of 11 clean refresh cycles on one machine, run at a deliberately low threshold so cycles came fast. On rc.1, a long session can still stall at the clear step and need a manual &lt;code&gt;/clear&lt;/code&gt;. The fixes for that are merged on master but not in a tagged release yet, and two narrower edge cases around the acknowledgement are still open (issues #90 and #91). I'm not claiming it beats compaction. It's a different trade-off: an inspectable checkpoint and a clean window instead of a summary. Each cycle also costs some tokens to write and read the capsule. The repo is at &lt;a href="https://github.com/wrg32786/aigent-os" rel="noopener noreferrer"&gt;https://github.com/wrg32786/aigent-os&lt;/a&gt; if you want to read the install script before running anything.&lt;/p&gt;

&lt;h4&gt;
  
  
  FAQ
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Does turning off auto-compact give me more room?&lt;/strong&gt;&lt;br&gt;
It doesn't change the model's context window. Some users say turning it off frees space that was held back for compaction. I couldn't confirm that in Anthropic's docs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Does &lt;code&gt;/compact&lt;/code&gt; still work with auto-compact off?&lt;/strong&gt;&lt;br&gt;
Yes. The settings reference says manual &lt;code&gt;/compact&lt;/code&gt; keeps working. Only &lt;code&gt;DISABLE_COMPACT&lt;/code&gt; turns it off.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What happens if I hit the limit with auto-compact off?&lt;/strong&gt;&lt;br&gt;
From what I can tell you get a context-limit error instead of a compaction, though the docs only spell that out in one place. At that point you &lt;code&gt;/compact&lt;/code&gt; or &lt;code&gt;/clear&lt;/code&gt; by hand.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Is a handoff file better than compaction?&lt;/strong&gt;&lt;br&gt;
Neither is better everywhere. A summary takes no effort. A handoff you control takes effort or tooling, but you decide what survives.&lt;/p&gt;

</description>
      <category>claudecode</category>
      <category>ai</category>
      <category>productivity</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
