AWS Builder Center

Customizing Kiro, Part 2: Safe Autonomy and Independent Verification

How do you let Kiro run overnight without surprises in your main branch? And how do you know its tests catch real bugs? Part 2 shows two patterns built on custom agents, hooks and a trust ladder, with configs you can adapt and a first look at Kiro Workflows.

Series: Customizing Kiro (2 articles)

  1. 2
    Customizing Kiro, Part 2: Safe Autonomy and Independent Verification This article
In  Part 1  I covered Kiro's building blocks, how to choose between them, and two patterns that combine them: a rule with a checker, and a specialist reviewer agent.
This part answers the two questions teams ask next: how do I let Kiro work unattended without unreviewed changes reaching my main branch? And how do I know its tests actually test anything?
Both answers build on the specialist agent from Part 1: a custom agent that does one job, with limits set by its configuration rather than by asking the model nicely.
As in Part 1, the steps of each workflow run across the top and the building blocks run down the side. Below the dashed line are the two actors: the Kiro agent, which does the work, and people, who make the decisions.

Pattern 3: Safe autonomy

Scenario: a nightly CI job starts Kiro to upgrade a dependency. By morning there is a draft pull request waiting for review, and nothing else has changed.


Nobody is watching this run, so nobody can approve a tool call. Instead of relying on approval prompts, you make the dangerous actions impossible.
  1. Scheduled start: a CI job starts Kiro CLI in  headless mode  with a dedicated  upgrade-bot  agent.
  1. Plan: the agent follows an  upgrade-procedure  skill, so every upgrade runs the same way.
  1. Change code: it follows the team's conventions from steering and works on its own  upgrade/  branch. A  PreToolUse  hook blocks pushes to main and edits to infrastructure.
  1. Verify: a  Stop  hook runs tests and lint. Failures go back to the agent, which keeps fixing until they pass.
  1. Publish: the agent pushes its branch and opens a draft pull request. A person reviews and merges it the next morning.

The agent is the safety boundary

 .kiro/agents/upgrade-bot.json 
{
"name": "upgrade-bot",
"description": "Upgrades one dependency on its own branch and opens a draft PR. Never touches main.",
"tools": ["read", "write", "shell"],
"resources": ["skill://.kiro/skills/upgrade-procedure/SKILL.md"],
"permissions": { "rules": [
{ "capability": "fs_read", "match": ["**"], "effect": "allow" },
{ "capability": "fs_read", "match": ["**/.env*"], "effect": "deny" },
{ "capability": "fs_write", "match": ["src/**", "package.json", "package-lock.json"], "effect": "allow" },
{ "capability": "fs_write", "match": [".kiro/**", ".github/**", "infra/**", "**/.env*"], "effect": "deny" },
{ "capability": "shell", "match": ["npm install *", "npm test*", "npm run lint*",
"git status", "git diff*", "git checkout -b upgrade/*", "git add *", "git commit *",
"git push origin upgrade/*", "gh pr create --draft *"], "effect": "allow" },
{ "capability": "shell", "match": ["git push * main*", "git push --force*", "rm -rf *"], "effect": "deny" }
] }
}
  • Deny rules always win. In Kiro, a deny in any scope overrides any allow, so the deny list is your hard floor.
  • Deny writes to  .kiro/ . Otherwise an agent with write tools can edit its own hooks, steering and configuration.
  • Keep allow rules specific. A broad rule such as  git *  would also let the agent push anywhere.
  • The hook is the backstop. Permission rules match command prefixes, and there is more than one way to write a push. A  PreToolUse  hook sees every call before it runs, blocks it by exiting with an error, and tells the agent what to do instead.
In CI, run the agent with  kiro-cli chat --v3 --no-interactive --agent upgrade-bot  and an API key, and leave out  --trust-all-tools . With nobody there to approve, anything the rules don't pre-approve is denied, which is exactly what you want. Hooks run in headless mode too, so make them return a clear allow or deny.

Earn autonomy one step at a time



For each kind of action, move up a step only when the agent has proven reliable at the one below: observe (it reports what it would change), recommend (it proposes, you act), act with approval (it acts, you approve each step), and finally autonomous (it acts, you review the outcome). A new kind of action, such as a major version upgrade instead of a patch, starts again at the bottom.
Why it works: least privilege beats approval prompts. If the agent can't do the dangerous thing, it can't do it by accident. The rules make it impossible, the hook catches what the rules miss, and a person still owns the merge.

Pattern 4: Independent verification

Scenario: build a feature from a spec. If one agent writes both the code and its tests in the same context, the tests share its assumptions. A misunderstanding in the code is mirrored in the tests, and everything passes.


Green tests can still be wrong. The fix is to split the work across separate custom agents, each with one job and limits that keep it in its lane:
  1. Approve the spec: a person signs off what should be built.
  1. Write tests: a  test-writer  agent writes tests from the spec, guided by a test-design skill. It can only write to  tests/ .
  1. Implement: an  implementer  agent makes the tests pass. It cannot edit  tests/  or  .kiro/ .
  1. Check: a  Stop  hook runs the full test suite.
  1. Review: a  reviewer  agent, in a fresh context, checks the change with a review checklist and can only comment.
  1. Merge: a person merges.

Each agent stays in its lane

A tool list can't restrict by path, so the lanes come from permission rules.
 .kiro/agents/test-writer.json 
{
"name": "test-writer",
"description": "Writes tests from an approved spec. Never writes implementation code.",
"tools": ["read", "write", "shell"],
"resources": ["skill://.kiro/skills/test-design/SKILL.md"],
"permissions": { "rules": [
{ "capability": "fs_write", "match": ["tests/**"], "effect": "allow" },
{ "capability": "fs_write", "match": ["src/**", ".kiro/**"], "effect": "deny" },
{ "capability": "shell", "match": ["npm test*"], "effect": "allow" }
] }
}
 .kiro/agents/implementer.json 
{
"name": "implementer",
"description": "Makes the approved tests pass. Never changes tests.",
"tools": ["read", "write", "shell"],
"permissions": { "rules": [
{ "capability": "fs_write", "match": ["src/**"], "effect": "allow" },
{ "capability": "fs_write", "match": ["tests/**", ".kiro/**"], "effect": "deny" },
{ "capability": "shell", "match": ["npm test*", "npm run lint*"], "effect": "allow" }
] }
}
The deny rule stops the write tools. To also catch a shell command that edits a test file, add a  PreToolUse  hook to the implementer's own configuration (inline hooks are supported in Kiro CLI V3), so it doesn't get in the test-writer's way.
For the reviewer, reuse the specialist agent from Part 1: read tools, a comment tool and nothing that can write. Give it a different model from the implementer if you can, so they don't share blind spots.
Run the three agents in turn, from the IDE or as pipeline steps. Each run starts with a fresh context, which is the point: the implementer never sees the test-writer's reasoning, and the reviewer sees only the result.

Where Kiro Workflows fits

You can also hand the sequence itself to Kiro.  Kiro Workflows  runs a plan of agent steps in the background, and each step runs in its own session with fresh context. That fits this pattern well: the test-writer, then an implementer that loops until the tests pass, then independent reviewers, with Kiro showing you the plan for approval before anything runs. Your custom agents still set each role's limits, and the strictest permission rule still wins.
Workflows is opt-in, so turn it on for your workspace first. I'll cover it in more detail in a future post in this series.

What to watch for

  • When a test looks wrong, a person decides. The implementer flags it in its summary instead of editing it.
  • Tests come from the spec, not the code. Give the test-writer the requirements and the public interface, not an existing implementation to copy.
  • Keep the Stop hook fast. If the full suite is slow, run the affected tests in the hook and the full suite in CI.
Why it works: AI reasons, deterministic checks decide, and people own the decisions that are hard to reverse. Splitting the roles makes each check independent of the work it checks.

Putting the two together

Read across the series so far and the three patterns form one arc, all built on the same idea of one agent per role:
  • The specialist agent (Part 1): one role, watched. The reviewer can read and comment, but can't write, and a person decides.
  • Safe autonomy: one role, unattended. The upgrade-bot can write, so its limits are tighter: narrow allow rules, deny rules, a backstop hook and the trust ladder.
  • Independent verification: several roles checking each other. The test-writer and implementer are specialists with one job each, and the reviewer is the Part 1 agent, reused unchanged.
They also combine. Point the nightly job at the three agents from Pattern 4 and you get unattended feature work: tests written independently, an implementation that can't change them, a review in a fresh context, and a person merging in the morning. Start with one pattern, earn trust, then add the next.

What's next

This is Part 2 of the series. The next part will look at other engineering personas.

Series: Customizing Kiro (2 articles)

  1. 2
    Customizing Kiro, Part 2: Safe Autonomy and Independent Verification This article
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article