Notes on making an AI agent ask before it pushes
TL;DR: I gave a coding agent on DigitalOcean's Managed Agents "ask" rules for git push and gh pr create. In the first run neither fired, because the agent chained both into one cd ... && git -c ... push && gh pr create command and the rules match literally. Wildcard patterns caught all three gated commands in a second run.
I wanted an AI coding agent to do the work by itself and stop only before anything left its sandbox: pushing a branch, opening a pull request, commenting on one. DigitalOcean's Managed Agents let you write that into the session spec as permission rules. You allow everything by default and set a few commands to "ask". I ran two sessions against a small public repo of mine to see how it holds up. The first set of rules didn't fire once.
How was it set up?
Each session was a Harness Runtime session with the claude-code harness, Claude Sonnet 5.5 through DigitalOcean's inference, the mars-2vcpu-4gb size, and GitHub access through an OAuth connection. The permission part of the spec looked like this:
permissions:
default: allow
rules:
- tool: bash
match: { command: "git push *" }
action: ask
enforcement: strict
- tool: bash
match: { command: "gh pr create *" }
action: ask
enforcement: strict
The task was a real issue on the repo: write pytest tests for decode() and trial() in flip.py, push a branch and open a pull request.
Why didn't the first run ask for approval?
The run took 54 seconds and 10 tool calls. It wrote 12 tests, got them passing, pushed the branch and opened PR #10. It never asked me anything about the push. This was its last command:
cd /workspace/bitrot-demo && git -c credential.helper='!gh auth git-credential' push -u origin tests-for-flip 2>&1 | tail -3 && gh pr create --title "..."
The docs say rules match the command literally, and that's exactly what happened. git push * only matches a command that starts with git push. This one starts with cd, has -c credential.helper=... between git and push, and puts gh pr create at the end of a chain. Neither rule matched, and both things happened.
None of that was the agent being sneaky. Plain git had no credential helper in the sandbox, so it used the gh login as a one-off helper for that one command, and it chained the PR onto the push because that's how people write it in a terminal. The problem is that what people normally type doesn't look like git push *.
One more thing in that run surprised me. The commit failed at first because git had no author set, and the agent asked me which name to use. The question came back as "The user did not answer the questions" in 7 ms, and the agent picked a neutral identity and carried on. I wasn't attached to the session, so nobody could have answered. But it didn't hold the run the way an approval does.
Did wildcard patterns fix it?
For the second session I changed the patterns to *git*push* and *gh pr *. The task was a small follow-up on the same branch: add a .gitignore, push it and leave a comment on the PR. I also told it to run the push and the comment as separate commands.
This time every gated command stopped and waited:
| # | Command | Asked | Answered | Waited | Answer | What happened |
|---|---|---|---|---|---|---|
| 1 | git push origin tests-for-flip |
08:07:49 | 08:11:13 | 3 min 24 s | approve | failed, no git credentials |
| 2 | git -c credential.helper=... push origin tests-for-flip |
08:11:19 | 08:11:31 | 12 s | approve | pushed |
| 3 | gh pr comment 10 --body "..." |
08:11:33 | 08:11:46 | 13 s | reject | not posted |
Request 1 sat for more than three minutes and nothing timed out. The run simply waited.
I approved a push that then failed, and the retry needed its own approval. An approval covers one exact command string, not "push this branch". If an agent tends to retry with small changes, you answer once per variant.
The reject went the way I'd want. The tool call came back as "denied". The agent didn't retry or look for another way to post the comment. It finished, said the comment wasn't posted, and printed the gh pr comment command for me to run myself. The whole run took 4 minutes 10 seconds, most of it waiting on me.
What do wildcard rules cost you?
*git*push* also matches git log | grep push, and *gh pr * also matches gh pr view. Neither came up in these two runs. None of the other five bash commands in run two matched by accident. But the wider the pattern, the more often it asks.
It's still string matching. A script file that runs git push, a shell alias, or a Python subprocess call doesn't have those characters in the command the agent sends. I didn't test any of those, but going by literal matching I'd expect them to go straight through.
So I'd treat these rules as a way to get asked, not as a wall. What actually limits the agent is the token in the session. The GitHub connection's default scopes include full repo. When I asked for only public_repo, the connection was refused with "requested scopes exceed provider maximum".
For comparison, 8 of the 10 tool calls in run one were bash commands. With default: ask, each of those would have needed an answer too.
What about approving from a phone?
The reason I tried this at all is that DigitalOcean has an iPhone app for Managed Agents, Cuttlefish, which is meant for approving an agent's next step from your phone. I answered all three requests from a laptop with doctl hr approve <session> <request-id> approve|reject, because I hadn't installed the app before the first request arrived. The 12 and 13 second waits are me at a terminal. I can't tell you what the phone flow is like.
What I got wrong
I wrote the rules as if a person types one command at a time. Agents chain commands, prepend cd and add -c flags.
I thought approving the push meant approving the push. It meant approving that one string, and the retry asked again.
I planned to approve from my phone and didn't install the app first. That's why request 1 waited three and a half minutes.
In run two I told the agent to run the push and the comment separately. That makes the wildcard result look better than it would have if the agent had chained them again. Run two doesn't show the wildcards catching a chained command, only that they caught the commands it ran.
And the GitHub connection link expired twice before I finished authorizing it. It's the last browser step, on GitHub's page, and it doesn't wait for you.
Caveats
Two runs, one harness, one model, one small Python repo. I didn't test other harnesses, best-effort enforcement, deny rules, or what the agent does when a request is deferred. The model tokens cost $0.13 for the first run and $0.05 for the second, plus a few cents of compute.
What I'd take from it
- Run the session once and read
doctl hr logsforhuman_input_requestedbefore you trust a rule. Zero requests is a result, not a pass. - Put wildcards on both sides of the pattern, and expect a few false alarms.
- Say in the prompt that gated commands should run on their own, not in a chain.
- Limit what the session's token can do. The rule gets you asked; the token decides what's possible.
FAQ
Do Managed Agents permission rules match the whole command or a prefix?
They match the command string literally, so git push * only matches commands that start with git push. A command that begins with cd or puts -c flags between git and push doesn't match.
Does an approval cover retries? No. In my run, an approved push failed and the agent's retry, with a slightly different command, raised a new approval request.
What does the agent do when you reject a request? Here it got "denied", didn't retry or work around it, and reported the command it would have run so I could run it myself.
Comments
Join the discussionRun 1 shows the limit of matching command strings: once the agent can use sh -c, a script file, a git alias or a Python subprocess, there's always another spelling of git push. Wildcards help, but the agent only has to be creative once, and it isn't even trying to evade you, it's just being efficient.
So I'd gate capability rather than text:
- Your last point, "the token decides what's possible", runs straight into the public_repo refusal. Until the connection accepts a narrower scope, the repo itself can still say no: a ruleset on main that blocks direct pushes and requires a pull request, with an empty bypass list so it also binds the owner's token, makes a push that slips past the rule fail on GitHub's side.
- Expose push as its own tool that takes structured arguments (remote, branch) and requires approval. Then the approval binds to the action, not to one exact command string, and a retry after a failed push doesn't need a new prompt for a different spelling.
- Treat "did not answer" as no. The 7 ms non-answer in run 1, after which the agent picked a neutral identity and carried on, is the case to block: a missing answer should stop that step, not choose a default.
A ruleset on main wouldn't have changed either run. Both pushed a new branch, tests-for-flip, and run one then opened a PR, which is exactly what that ruleset asks for. It stops a push to main, and neither run tried one. For the case in the post it would have to cover creating and pushing branches too, and I haven't tried a ruleset that does. Agreed on the other two. A push tool with structured arguments would also have fixed the retry in run two, which needed a second approval only because the command string changed. And I didn't find a setting that makes an unanswered question stop the run, so for now that would have to go in the prompt, which is a weaker place for it.
Fair point, I read the ruleset as covering more than it does. It only blocks a push to main, so neither run would have hit it. Branch creation can be restricted separately, but only by targeting all branches, and then every new branch needs a bypass or an approval, which gets noisy. A push tool with structured arguments sounds like the cleaner fix. And agreed that putting "stop on no answer" in the prompt is the weaker place for it.
So when the ask timed out in 7 ms, the agent picked an author identity by itself. Does anything in PR #10 show that was its guess and not your choice?
Nothing that says it was a fallback. Both commits on PR #10 are authored as Claude <noreply@anthropic.com>, the PR was opened from my account because that's whose token the session had, and the description ends with the Claude Code footer. None of that says the author was a default the agent picked after an unanswered question. The only place that says so is the agent's final message in the run log. Someone reading the PR later would assume I chose it.
That real command trace shows why naive command-prefix allowlists fail even with a completely benign agent: prefix-matching git push * misses chained shell commands starting with cd and inline -c flags without anyone trying to bypass a rule.
Even wildcard patterns on bash strings are fragile because shell quoting, subshells, or scripts can still hide a push. For high-stakes boundaries like pushing branches or opening PRs, enforcing permissions at the credential or API-token scope—holding write tokens behind an approval proxy rather than inside the shell environment—is far harder to trip over accidentally.