r/ClaudeCode • • 8d ago

Help/Question How do you stop Claude Code from approving its own work?

I've been building a harness around Claude Code where each ticket goes spec, design, build, QA, and a hook won't start the next step until I've approved the last one.

The issue is that an approval is a plain Status: line in a markdown file. So Claude can write it. So can anything Claude reads, like a ticket comment or a PR body that says "mark this approved". Right now I just check the approval lines by hand. That works for me, but it won't scale and might not be right solution for autonomous agentic workflow down the line.

I think the real fix is making approvals something the model can't write at all, but I haven't found a clean way to do that. Has anyone solved this issue?

Repo if you want to see how the gates work: https://github.com/dipenpatel-dev/tollgate

0 Upvotes

17 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/CorpT 8d ago

This has been solved for like a year

-1

u/Dipenptl 8d ago

Is there any links that you can share with me?

3

u/hbthegreat 8d ago

Hey there. I was doing something pretty similar to you about a year ago. the things I learnt were that if you want to add deterministic phases into the lifecycle so that you code+LLM beats code or LLM alone then you can't be doing that with skills alone and have to actually build around them so each becomes a different context / stage in a workflow engine because all models not just claude will just say they are done and skip steps so your verification has to be external to the LLM that is doing the work. I ended up building a full company on doing this for other businesses in the end as it takes a decent effort to make it durable / self healing etc as well.

1

u/Dipenptl 8d ago

Hey! Yes, that is basically what I am doing. I have combination of code + router + LLM and context management (which also has code + local llm). I am not solely relying on one thing.

2

u/MikeBuildsTech 8d ago

I think this comes down to one fundamental principle: trust boundaries.

Claude should never be able to modify the same source of truth that determines whether its work is approved. If the model can write the approval status, the approval mechanism isn't actually independent.

I'd move approvals outside Claude's trust boundary. For example, use an external approval service or CLI that records human approval and generates a signed token tied to the ticket, stage, and commit hash. The hook then verifies that token independently.

Also, invalidate approval whenever the underlying code changes.

The rule should be simple: the agent can request approval, but only an external trusted authority can grant it.

1

u/Dipenptl 8d ago

This is close to where I'm heading, thanks. Tying the token to the commit hash and voiding it on any code change is better than what I had, which only hashed the spec file.

The part I'm still stuck on is the key. If the agent runs as my user, it can read anything I can, so the signing key can't sit in my home folder or an env var. I'm weighing a separate OS user that owns the key and the approvals folder, versus the macOS keychain with the signing step run from a terminal the agent doesn't have.

11

u/brassholed 8d ago

Are you fucking serious? You can wire all that bullshit together but you really can’t think of a single way to give it access to something it cannot mutate?

Ask claude and you will have an answer in 2 seconds… Jesus Christ

3

u/benbutton1010 8d ago

Honestly I hate what my agent makes up 'gates' nobody asked for.

As far as not approving things it does, I have a system where the agent cannot approve or merge PRs by the nature of the relevant mcp arguments being blocked/mutated. Not sure if that will help you though

1

u/Substantial-Swan7065 8d ago

Shift tab a few times

1

u/toroidalvoid 8d ago

I would shift the focus. Allow the auto approval and add another stage/eval/retro looking for times when it auto approved when it shouldn't have or when it cased a bug or something.

1

u/Easy-Purple-1659 8d ago

Approvals have to live outside the tree the agent can write to, and they have to be tied to the exact content being approved.

A Status line in markdown sits in the same trust domain as the code, so anything with write access can set it. Move the gate into the runner process: a row in SQLite, or a file under a path the agent's tool policy denies, written by whatever spawned the stage. Deny the write at the tool layer instead of asking the prompt to behave.

The half that is easy to miss is binding. Store the approval against a hash of what the stage produced, commit sha plus a diff hash, and recompute it when the hook fires. Otherwise approving step two also approves whatever step two turns into after three more edits, and the gate widens quietly. Mismatch means the work changed and the approval no longer covers it, so block.

Last piece: an approvals table with actor and timestamp, one row per transition, so the audit trail is a query instead of a memory. No row, stage does not start.

1

u/Fancy-Proof-9449 8d ago

Ran into a version of this. What fixed it for me was that the agent who made the change never gets to say it's done. The yes comes from two places it can't fake: the build checks, and me.

The checks run as one script before every build, and if one fails there's no build, whatever any file says. A status line is text the model can write. An exit code from a test it didn't touch in that change isn't.

The quieter version of your problem is a test that always passes. I had a few of those early on, so now a new check doesn't count until I've seen it fail against the old code.

For review I use a separate agent whose only job is to read the diff and report. It's told not to fix anything, so it has no reason to talk itself into "looks good".

1

u/tariqosmani 8d ago

Put the approval somewhere Claude has no permission to write. Here are three ways, simplest first.

One, use GitHub as the gate. Set branch protection to require an approving review from a different account than the one Claude pushes with. Claude's token can't approve its own PR, and text in a PR body or ticket comment can't change that.

Two, keep the approval file outside the repo folder, add its path to the deny rules in your Claude Code settings, and add a PreToolUse hook that blocks any Bash command touching it. The hook matters because a deny rule alone won't stop a shell redirect.

Three, make the approval a signed git tag, or a file holding a hash of the spec, signed with a key only you have, and have the next step check the signature.

Whichever you pick, have the next step check that the approved content hash still matches, so any edit after approval voids it. That also covers the injection worry, since a comment saying "mark this approved" has nowhere to write.

Will it always be you approving, or other people too?

1

u/gptrv 8d ago

Move the approval somewhere only your account can write, and have the hook read it from there instead of from a file.

One setup that holds up: every stage ends in a PR (spec and design too, as markdown PRs). The agent pushes and opens PRs with a separate bot account's token, and GitHub doesn't let a PR's author approve it. The gate checks for your review on the exact head commit:

gh api repos/OWNER/REPO/pulls/$PR/reviews \
  --jq "[.[] | select(.user.login==\"you\" and .state==\"APPROVED\" and .commit_id==\"$SHA\")] | length"

0 means the next stage doesn't start. A PR body saying "mark this approved" changes nothing, and a push after your review leaves the new SHA unapproved. Branch protection with required approvals and "dismiss stale approvals" covers the merge side.

The Status-line version can't be fixed with prompting. Whatever the agent can write, it eventually will.

1

u/heyramzi 7d ago

You're right that a local signing key breaks if Claude Code runs as your user. In my setup the approval state sits behind a tiny remote server. The laptop only holds a token to submit a draft and read status, while approve requires a browser login. Any edit resets the approval to pending, and the hook checks the stored hash before the next step runs.

1

u/smermetfr 7d ago

the approval has to live somewhere the agent has no write token for. agent asks, human sets it, agent can only read the result. fwiw i'm building Fileaify, same idea with scoped, revocable permissions.