r/ClaudeCode • u/nimbus6446 • 8d ago
Help/Question Question about unattended agents
I have a problem figuring out how to have a agent finish a really long task. We are talking hours of work. I tried different things, splitting the job in smaller chunks then having a loop go over ot, then some workflow stuff but none aval. How do you use it? Do you have a good setup?
2
Upvotes
•
u/AutoModerator 8d ago
Hey! Thanks for posting to r/ClaudeCode
While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.
For help, project discussions, tips, and general chat, join the ClaudeCode Discord.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
2
u/Outrageous_Band9708 8d ago
https://github.com/Druthulu/ProjectArchitect
my solution works perfectly for your use case.
its an amazing planner, and orchestrator, and token saver.
it uses very strict serial subagents and uses two plans. the roadmap which I call a generational plan. this is things like 1.0, 2.0 etc. and phase plans. this is things like 0.1, 0.2. each phase builds a piece of the final software that later phases need to stand on.
no compact, no clear, my system has an infinite main session length, this is because nothing ever touches the main session context. the mod system intercepts your messages and spawns a subagent to read them. it will automatically rotate that agent ever 300k, never cold cache reads, cache warming system and best TTL per agent type.
best part is, you don't need to change how you work. there are no slash commands or skills that you must remember to invoke, it just works.
the mod system enforces all best practices and creates a workflow that you can set and forget.
autopilot mode is the default, but you can ask for coop mode or switch anytime between them. coop mode allows you to be involved every turn.
the plan gets built and you approve or make changes, and then it can just work infinitely without issues.
highly recommend you checkout the readme and the wiki and test it out yourself.
1
u/nimbus6446 6d ago
Thanks everyone for suggestions. In general, I have a deterministic workflow that I build and then execute. It is very similar to Claude workflows, but the main difference is that my approach has checkpoints that can add additional sub-operations, like 3.1 "fix the failing tests" before we go to 4.0. Everything is logged and saved in step handoffs. In the end, I do a pass over it, and then the output is either discarded or converted into architecture decisions or documentation, depending on the task.
1
u/bvrai_dot_ca 8d ago
Good set up is have is plan the work first, then work towards the big objective, every time the context needs compacting reinject the plan and other critical portions of the system prompt. Make sure your agent has cacheing set up or it will fill the context window with redundant information. Also, you need an evaluator agent at the end since agents are biased and unable to accurately assess whether their own work is completed properly, so an evaluator will stop the execution agent from stopping if it thinks the task is done when it isn't. Depending on how complex, may need to use more subagents for different parts. There's a lot more to effective harness engineering but if you paste that to Claude or codex it may able to get you going in the right direction. Also, critically make sure you have a good model with the effort/reasoning level set high because weak agents on low reasoning struggle to stay on task doing constructive work for long periods of time.
1
u/Gifted_Diplomat 8d ago
I had to make my own uber harness, it uses an "architect" model that can call a cloud api or lower harness like Claude cli. That breaks the task into a bunch of smaller steps and writes a to-do list in a markdown file, and then it switches to a local model using a sub harness like open code that loops over it and then tests itself. There's a setting so if it can't figure out how to do the task, it escalates to a different model. Generally it works pretty well for long agentic loops. I just check it in the morning.
1
u/MikeWise1618 8d ago
I always have it plan things out and break everything into steps. I then give approval to continue after each step, and usually I look at intermediate results. This allows me to make adjustments. I run two or three of these things at a time.
No agent should be "unwatched", whereby it doesn't have to be a human doing the watching. But my "agentic sheepdogs" still need work.
1
u/lycheedorito 8d ago
Have it delegate to a single subagent, so it can always monitor progress, and /goal Complete the task to the best of your ability without my input
1
u/TheMadSaiyantist 8d ago
"Do not stop until x" and also monitor it with another agent if it goes sideways
1
u/___zuki 8d ago
You have to set a well defined goal which specifies acceptable things to stop at and things you give it permission to do. This is normally a fairly fixed list for your workflow/repo, so create a skill “unattended” which holds your defaults. Then it’s just “/goal /unattended implement plans x, y, z”.
1
u/SirRobinBlibs 8d ago
What helps most is moving the state out of the conversation. Keep a plan file with small steps, each with a command that proves it's done, and have every iteration read the plan, do one step, run the check and tick it off. Then it doesn't matter much if a session compacts or ends, because the next one picks up from the file.
For the "it just stops" part, a Stop hook can block the stop and hand back a reason, for example while tests fail or unchecked steps remain. Add an iteration cap so it can't loop forever.
1
u/CCodeSI 8d ago
The long runs that work tend to share one design choice: the progress lives in files, not in the conversation. Then it doesn't matter if a session dies, compacts or drifts, because the next one picks up from disk.
What that looks like in practice:
while grep -q '\[ \]' TASKS.md; do claude -p "Read TASKS.md and NOTES.md, do the next unchecked item, run the tests, update both files, commit."; done. Each iteration starts with a clean context, so there's no slow drift over hours, and one failed item doesn't poison the rest.The chunking you tried was the right instinct; usually what's missing is the external state plus fresh context per chunk.
1
u/xqianliu 8d ago
I stopped trying to make one session run for hours. Here's the setup I run:
I split the work into tickets first, each sized so one run finishes it. One ticket means one worktree and one PR, and the acceptance criteria live on the ticket, not in my head.
During a run the agent is not allowed to ask me anything. If it can't decide something, it writes the reason on the ticket and stops, and I decide. If a run dies halfway, the progress comments and run log on the ticket are the state, a fresh session picks up from there.
The agent commits once at the end, so a dead run has no half PR to clean up.
I'd start with that instead of a loop over chunks. The loop only makes sense when the pieces are already separate tickets.
1
u/AryanThakor 8d ago
what made long runs work for me was a progress file it updates after every step (done, next, blockers) plus a check command it has to pass before it marks a step done. when the session dies or compacts, a fresh one reads the file and carries on instead of starting over
1
u/Excellent-Issue-5956 8d ago
One thing I didn't see here is the usage limit. If a long run hits the 5 hour limit at night it just sits on the limit message until you're back, and in my terminal there's no way to type into a stuck session from outside.
So I wrote a cron script that looks for sessions whose last transcript entry is the rate limit error, waits until the reset time, then starts a headless claude -p in the same folder that resumes that session as a fork. The prompt it sends says the limit reset, carry on where you left off, nobody can answer questions so make the call and note it, don't push or send anything, and end with what's done and what's left.
I only had it on for one night and nothing hit the limit, so it never actually had to fire. But that's the part I'd add on top of the progress file if your runs go for hours.
1
u/i_hav_tegridy 8d ago
what worked for me is not making it one long session at all. split the job into tasks in a tracker (i use beads,
bd readylists whatever isn't blocked) and give each task a done check it can't fudge, like tests pass or a file exists. then the loop is: take the next ready task, do it, close it with a short note on what changed, repeat.if a session dies or compacts nothing is lost cuz the state is in the tracker, not the chat. a fresh session just reads the open tasks and carries on.
two more things: run it on a machine that stays on, not a laptop that sleeps, and tell it to mark a task blocked and move on when it needs you instead of guessing. then you only check in when something is actually waiting on you
1
u/morkeeth 6d ago
ha, mine got stuck pressing enter. happened 2 times. i could see the next job just sitting there in the worker's terminal and the other agent kept trying to send it. there's the whole job, typed out, and the worker's doing absolutely nothing.
i want the worker to tell me which chunk it just started before i walk off. the other session can say it handed the job over all it wants. i can still see the damn text in the box.
0
u/Dutch-man 8d ago
I just wait. Sometimes it takes fucking ages. I’ve had tasks that have taken 5 days. Also you can type “progress?” To get an idea of where things stand and if it’s started to drift.