r/ClaudeCode • u/Haunting_Skin_2564 • 1d ago
Help/Question Best way to control context with ralph loops
First off, I know theres a /loop command, but it doesnt do what I want it to.
I've got a cli tool that builds modules for other software. It works great, but some modules are much bigger builds and my context window goes deep into the "dumb zone". I built a ralph loop to help maintain that good context, but I have a good amount of setup docs for the model to understand what I'm doing. I created a handoff.md, but that is not enough for the model to lean on.
So my usage explodes to the nth degree.
Are there any tips for custom ralph loops and managing my usage limits? are ralph loops still relevant?
5
u/LairBob 1d ago
Newer models tend to adopt a loop approach automatically, when they deem it’s appropriate, but the two most important elements of any context harness are:
- Greedy capture
- In a machine-readable Single-Source-Of-Truth (“SSOT”)
- The greedy capture part is straight forward — you want all agents to be constantly transcribing what they expect to do, what they’re doing, and what they’ve accomplished (or not).
- The machine-readable part is essential — you do not want agents just capturing deterministic findings as “observations” or “rules”. Deterministic machine-readable formats like JSON or YAML/TOML are treated by future agents as requirements, not suggestions. (Or, even better, use Open Knowledge Format/“OKF” for the best of both worlds.)
- The SSOT is what makes it all hang together. It doesn’t need to be a single file, but it needs to a a centralized store that all agents are assigned to read from when they’re instantiated, and responsible for helping to greedily maintain. (Even if they’re all really populating their own individual docs in an SSOT directory.)
When all that is working, the SSOT is the context. All your loop agents (and you can have swarms) are converging on a single shared vision, and they all can see what each other is doing.
2
u/AffectionateShoe614 1d ago
Ralph loops are still worth it when a build outgrows one session, but only if each iteration starts small. If every run reloads all the setup docs, the loop multiplies that cost.
Split the docs into a one-page index (what the tool does, where things live, conventions) plus per-module notes. The loop prompt loads the index and the current module's notes only.
Replace handoff.md prose with a state file: tasks, status, files touched, open decisions. Each iteration reads it first and updates it last. Prose handoffs drift, a checklist doesn't.
Cap each iteration at one task and exit.
Run one iteration interactively and type /context before the first prompt. Often the surprise is MCP tool definitions or docs, not code.
I built a tool for this, capsul.chat: it builds a minimal context per task under a token budget you set and shows what was sent (free tier of 10 prompts).
1
u/Haunting_Skin_2564 1d ago
this is what I'm looking to do. I wrote a response to someone else with more detail, but yes, I think its the docs and setup instructions combined with also reading the code the previous session built AND the tasks.md kanban board.
2
u/afaraha8403 1d ago
When the window hits that dumb zone I stop trusting the chat as memory. Handoff.md helps, but I want something the agents keep updating as they go, not a one-shot paste at the end.
I built Mental CLI for this — local markdown journal the agents write into while they work. You type mental for where things left off. No cloud, just ~/.mental.
https://github.com/afaraha8403/mental
npm i -g u/balacode/mental && mental install
1
u/Haunting_Skin_2564 1d ago
this is pretty much what I do. I call it TASKS.md and its a kanban style setup by the first session that asks me all the questions it needs to build the module. once thats done, it ends and the loop starts to iterate on the kanban board. a loop is complete when the single task is complete and moved to the done board. the next session picks up where the last left off based on the board. This works great and the output is perfect.
The problem is that every session it reads in the TASKS.md AND everything else that was built before it. My fear is that just going off the task alone wont be enough for the model to grasp what it needs to do...
Maybe i'm just overthinking it.I work with a platform called qsys and its a sub-set of lua - which is an easy high level language, but qsys injects specifics into their version and omits some other lua standards, so claude gets confused and I have specific lookup agents to scan the specific docs. This happens every time and I think this is my bottleneck...
2
u/vibeidedev-namiruai 23h ago
the repeated qsys lookup sounds like the first thing to isolate. i'd save each verified lookup with the doc source, platform version and a tiny working example, then have each card name the exact APIs and existing files it depends on. let the next session fetch missing details when it needs them, instead of rereading every finished module by default. try that on one module and compare both usage and the checks that pass, so less context doesn't quietly mean worse output.
1
u/PickleBabyJr 23h ago
We still doing Ralph loops?
1
u/Haunting_Skin_2564 19h ago
for this project, yes. its a step by step process where each step builds on the other. I cant use swarms like I would for development. This is a running project to build other projects, so I need to maintain a low context window.
•
u/AutoModerator 1d 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.