frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

Open in hackernews

Cutting (Claude Code) token spend on dynamic workflows 80%

2•gojkoa•8h ago
Discovered something very interesting by chance a few days ago, and thought it might be interesting for other people running dynamic workflows with claude code. The workflow scripts themselves are javascript. Claude code knows the format and it can make a tool that composes workflows instead of going through LLM each time.

I got it to do that, and with a few more tweaks it got the token spend for workflow execution and monitoring down to about 20% of what it was before, significantly speeding it up (most of our workflows used to take 5-6 hours, they now take 20-40 minutes).

We got Claude to analyze the workflows from the past few weeks (the workflow execution is on disk, in ~/.claude/projects) and identify commonalities between them. It turned out to be effectively 3 kinds of workflow steps, done in a million ad-hoc ways.

- a code change agent/implementer/worker - this takes a task from the plan and does it; such agents can run in parallel

- a check gate agent - this tries to figure out what the implementer agents did and evaluates things that should not be done in parallel

- the final check, which deploys, runs api tests etc.

It also turns out you that Claude can compose workflows out of standard "agents" (from ./claude/agents), not writing the prompts for workflow agents by LLM each time; so I asked it to figure out commonalities/variabilities, and it wrote 3 agent scripts, which we later reduced to two:

- workflow-worker - gets a piece of the plan and very tight permissions to only write and run tests for it's own part of the plan/file boundary, and not fix anything that others might be doing, and definitely not run the whole test suite

- workflow-gate - gets the results from parallel workflow agents in a group, runs serial verifications based on what changed in git (e.g. if any www files changed run web tests; if any backend files changed, run api tests etc. This used to be custom-written by LLM each time but we moved it to a makefile with two targets, so make workflow-serial-gate checks the git tree and runs tests for changes, make workflow-final-gate runs clean tests on everything, deploys to a staging environment, runs post-deployment tests

as the variability moved into the makefile, both of these agent definitions became standard 100-line markdown, that the LLM did not need to write each time.

next, since the agent definitions are standardized, we got claude to actually write a tool that would read out the plan file with steps and dependencies, and write the workflow javascript directly. previously it used to take 10 minutes for something like this to come back for complex plans, now it takes a second.

Since the workflow agent prompts are static and written once, no tokens get spent writing them. since the whole choreography of which tests to run when is in the makefile, based on git changes, no tokens get spent on that. since worker agents are getting the plan and a step number, no tokens are spent telling them what to do (besides them reading the specific step, but this is unavoidable). Tokens get spent pretty much only on creating the plan, narrow implementation tasks and contextually fixing issues.

When a named agent runs as part of the workflow, the context passed to pre-tool use hooks includes the name of the agent (e.g. workflow-worker, workflow-gate) so we were able to constrain them significantly. For example, workflow-worker is not allowed to run make, or run the entire test suite, with a message to delegate that to the gate agent.

The end result is amazing, workflows run much much faster and spend far fewer tokens than before. Claude pretty much wrote the whole thing itself, so I definitely recommend this as an experiment if you run dynamic workflows. Happy to provide any additional info if people are interested.

Comments

jaredsohn•6h ago
I was thinking about this when I read a post about what would happen if all of a sudden AI stopped working.

I think we're building a lot of tools with AI that could have been useful without it; it was just hard to justify spending the time building it before in most situations.

gojkoa•5h ago
definitely. we built a custom eslint parser for scss, html, liquid and yaml and are using it to validate all sorts of rules that were previously just in people's heads. now they are codified and provide instant feedback. if we stopped using AI now, those would still be incredibly useful for human coding.

Ask HN: UK Rescue Rocket Sheds/Houses Information

20•burnt-resistor•4h ago•6 comments

Ask HN: How do you manage skills files?

9•imadtaieber•4h ago•8 comments

Ask HN: Show your micro-SaaS (September 2026)

5•genekrapivin•3h ago•0 comments

Ask HN: Who is using MCP in production?

189•sukit•3d ago•195 comments

Ask HN: Resources to get good at soldering?

268•tosmatos•4d ago•164 comments

Ask HN: What are you working on? (September 2026)

4•meerita•5h ago•3 comments

Ask HN: Why were OpenAI, Claude, and Grok simultaneously down?

400•halcdev•3d ago•703 comments

Ask HN: Who is hiring? (September 2026)

248•whoishiring•5d ago•346 comments

Ask HN: Are we normalizing surveillance in the name of safety?

2•dennysora-main•11h ago•2 comments

Ask HN: Who wants to be hired? (September 2026)

111•whoishiring•5d ago•482 comments

Ask HN: What's the best place to learn about skills and AI for coding in general

4•rrmdp•4h ago•4 comments

Tell HN: I want to see the same moon as you

14•UnderABlueMoon•1d ago•12 comments

Astra still fails at creating acceptable Rotational Ambigram

3•das_vicky•11h ago•3 comments

Tell HN: Both recent GCP outages caused by fiber optic maintenance

19•fastest963•3d ago•1 comments

Ask HN: Are others seeing Google's reCAPTCHA rejecting Firefox users?

71•Animats•3d ago•23 comments

Cutting (Claude Code) token spend on dynamic workflows 80%

2•gojkoa•8h ago•2 comments

Ask HN: 30, burnt out, with 6-10 months of runway. What would you do?

31•throwaway_30yo•4d ago•26 comments

Ask HN: Any Alternatives to Archive.ph & co?

7•hebelehubele•1d ago•4 comments

MITx is ending access to its courses for learners in Iran on September 8

5•mahdihabibi•1d ago•2 comments

Are people who only seem happy when they're angry increasing? Seems like it

4•Webstir•10h ago•4 comments

Ask HN: Who is using FPGA for ML inference?

10•softwarewright•3d ago•15 comments

Ask HN: Founders that raised funding and shutdown, did you raise again?

18•asim•3d ago•1 comments

Ask HN: How do you build organic traction as an indie dev?

7•charm137•1d ago•5 comments

Ask HN: What is the ideal email domain setup?

7•bix6•2d ago•5 comments

Ask HN: How have interviews changed over the last year?

12•mikodin•1d ago•0 comments

Tell HN: NVIDIA's Acquisition of HuggingFace was for $HuggingFace

43•MontagFTB•3d ago•4 comments

Xfinity silently blocks lots of new domains

15•dschwartz18•2d ago•6 comments

Ask HN: Is AI a Powerdrill?

4•dfps•1d ago•3 comments

Ask HN: Books Recommendations?

7•washelterskelte•1d ago•11 comments

Fable hacked my piano, can I release the results?

5•jmpman•1d ago•6 comments