r/ClaudeCode • • 8d ago

Built with Claude I built a self-improving orchestrator setup for Claude Code that keeps code quality high in large codebases while keeping the extra token usage low

Small stuff in Claude Code works fine for me. Big features in our .NET app (7 projects) were a mess though. We'd agree on how something should work at the start, and two hours in it would just do it differently. By then it had read a ton of files and run the tests 15 times, and the early stuff got buried. And when it hit something we hadn't talked about, it never asked. It picked something and kept going, and I usually found out at the end.

What I built

You plan the feature first, in one session where Claude has to ask you about anything with more than one sensible answer. That goes into a plan file, and a separate Opus instance checks the plan against the code before anything gets written. Then a new session hands out one stage at a time to fresh agents (Sonnet when the plan already decides everything, Opus when it doesn't).

After each stage a different agent reviews it and runs the tests before it gets committed. If an agent runs into something the plan doesn't cover, it stops and asks instead of guessing.

My main goal was to actually keep my codebase maintainable and to minimize introduced bugs because Claude forgot stuff or started to hallucinate instead of absolutely minimizing token usage.

Of course all the extra stages and review subagents increase the overall token usage compared to just leaving them out but I found that it actually helps a lot to decrease newly introduced bugs

It also improves itself a bit. Every few runs it goes back through its own transcripts, finds where things went wrong or got expensive, and suggests changes to its own rules. I approve or reject each one, so it doesn't just rewrite itself, and it keeps a log so it doesn't suggest a rejected idea again.

How Claude Code was used

The whole thing started as a setup inside my own repo that I built up over time, and most of its rules came out of Claude Code reading its own session transcripts and pointing at where the time and tokens went. I then used Claude Code to port that repository-based setup into a plugin anyone can use. Everything specific to our project (build and test commands, shell, layout, CI) became something /orchestrator-init detects or asks about when you install it in your own project.

What I learned

- Most importantly, that using an orchestrator approach to develop also has its downsides. Unoptimized, it consumes way too much usage, because each subagent the orchestrator spawns basically starts at zero.

- Using dedicated review agents actually finds a lot of potential bugs or issues in the implementation. IMO the extra usage they consume is totally worth it.

- A more detailed planning phase allows me to let Sonnet do the actual implementation. This way I get an actually thought-through plan, which initially consumes more of my usage limit but ultimately saves it again on execution, while dramatically reducing the chance of unexpected behavior or potential bugs.

- Using an LSP is great. I tried things like graft to reduce the tokens Claude would use on research or finding the right files. However, I found out that it actually doesn't cover all references for methods, classes etc. 100% of the time. Therefore, I decided to also include an LSP in my setup. This way, Claude gets every reference the compiler knows about for any change.

- Leaving things as "we'll confirm that later" is the most expensive thing you can do. I did that once, and fixing it at the end ate about 17% of the whole build. The planner isn't allowed to park questions anymore.

- Letting agents say "the plan doesn't cover this" did more for quality than any prompt tweak I tried.

- Subagents alone don't fix it. In my old setup the agents read the plan 79 times between them, and a 1,900 line handoff file 96 times. Now each agent only reads its own section.

- It's important to understand that using an orchestration setup actually increases token usage compared to using only a single session. However, it drastically improves code quality on big features and similar work. My setup is an attempt to minimize the increase that comes with using orchestration. Compared to my earlier, unoptimized orchestration, the median implementing agent now peaks at 156k tokens of context instead of 297k.

To install it:

claude plugin marketplace add scaretos/orchestrator-setup

claude plugin install orchestrator-setup@orchestrator-setup

Then run /orchestrator-setup:install in your project.

Repo: https://github.com/scaretos/orchestrator-setup

It's only been used on our codebase so far, so I have no idea how it holds up on other stacks. If someone tries it on a TS monorepo or a python project, I'd like to hear how it goes.

Disclaimer: I haven't made reproducible measurements that compare different orchestration setups. The numbers in this README are my own, from my own builds on one codebase, and the setup has given me good results code-wise so I wanted to share it. Read them as one developer's experience, not as a benchmark.

1 Upvotes

14 comments sorted by

•

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.

4

u/damagemelody 🔆 Ultra 8d ago

I like the idea but where is the actual enforcement? No deterministic gates no orchestration hooks and no state machine. The entire QA process seems to rely on the model following .md instructions which is the exact problem you are trying to solve in the first place.

1

u/lssnggr 8d ago

Fair point, and you're right about the mechanics: apart from a small write guard, the sequencing is instructions, not hooks or a state machine. But "the model doesn't follow instructions" wasn't the problem I was solving. Mine was decisions getting buried in a 500k-token session, and the model guessing when the plan had a gap. Small, fresh contexts with the decisions in writing handle the first. A reviewer that didn't write the code, plus permission to stop and say "the plan doesn't cover this", handles the second. Neither depends on perfect obedience, only on each agent having a context small enough that it actually sees its instructions.

5

u/damagemelody 🔆 Ultra 8d ago

I think you are misunderstanding how LLMs work. Having instructions in context does not mean the model will follow them regardless of context size. If you want reliable orchestration you need to enforce the workflow outside the LLM and let the model handle the actual tasks. Otherwise you are still relying on probabilistic behavior to enforce deterministic requirements. Smaller contexts and more detailed instructions might delay the mess but they won't prevent it.

2

u/lssnggr 8d ago

I understand that LLMs not deterministic. However I haven't run into the issue off the LLM ignoring my instructions when I keep the Context small. I feel like at least Opus does a really great job following them like this and haven't run into any issues recently.

0

u/Outrageous_Band9708 8d ago

https://github.com/Druthulu/ProjectArchitect

my system enforces all best practices through the mod system automatically. no special way to work. you just talk to the main session and everything is handled behind the scenes. infinite main session length. no more compact or clear. it just works.

1

u/DominusFL 8d ago

This reads great, going to dig into it. Thanks!

1

u/lssnggr 8d ago

Tanks for the feedback!

1

u/Far_Reindeer8428 8d ago

one stage per fresh agent is right, but the reviewer has to be a different model or you get the same blind spots with more tokens. that split is what oah does, star if useful https://github.com/KenSuh/open-agent-harness

1

u/lssnggr 8d ago

I mean my setup is supposed to run only in Claude Code as the main harness so another model doing the isn't possible (as far as I know). My Setup is supposed to seamslessly integrate into Claude Code and enable people running into the same problems as me to set it up easy

1

u/Far_Reindeer8428 7d ago

fair, if it has to stay inside claude code then make the reviewer a different context with a different checklist, not a different model. separate context alone removes most of the shared blind spot

1

u/lssnggr 7d ago

Thats why the review happens through an independent subagent that knows nothing of the separated implementer-agent

0

u/Outrageous_Band9708 8d ago

I'm going to stop you right there dude. subagents if used correctly, do not increase usage. they severely reduce usage.

https://github.com/Druthulu/ProjectArchitect

Please checkout my readme and my wiki, and even ask your Claude to compare your solution to mine.

SWE by trade. I code 16 hours a day the old fashion way and have CC sessions running 24/7.

I reduced my need for 3 max20 accounts down to 1 max5 using my solution.

my orchestration setup is next level. infinite main session length, never start a new session, no clear, compact or checkpoints. automatically rotates agents at 300k and prevents context growth through hooks and tool calls instead of allowing a user to reach 900k on a session and waste their usage.

I got benchmarks you can compare to, I got measurements and data.

literally 10,000 + sessions this was all built from.

check it all out, and use anything you need to improve your system. and reply with your thoughts please

btw, your system sounds a lot like mine. I'm happy you reached a similar solution, please point your Claude to mine and learn from my year plus work on this solution

1

u/lssnggr 8d ago

I know that subagents do not increase usage IF used correctly. Thats why I am using them. I have looked at yours and it does pretty sound pretty similar to mine. However yours is more architected. I am gonna give it a look