Recipes · Chapter 41 of 63
Run Kiro CLI Headless in CI
Run kiro-cli chat --no-interactive in a pipeline: authenticate with KIRO_API_KEY, trust the smallest tool set, and fail fast when MCP servers are missing.
Advanced 3 min read last reviewed 2026-09-04
◎ Learning objective
Add an unattended Kiro step to a CI pipeline with narrow tool trust and a fail-fast MCP check.
Headless mode runs one prompt and exits, which is what a pipeline step needs. Give it a key through the environment, trust the smallest tool set that does the job, and it behaves like any other CI command.
When to use this
Use headless runs for unattended, repeatable work: nightly documentation regeneration, triage of new issues, a scheduled check on a codebase. Do not use it as a substitute for a human reviewer on a pull request that ships. An agent step in CI is automation, and automation needs the same suspicion as any other unattended process.
Steps
-
Get an API key and store it in your CI secret store. Never commit it and never echo it in a log.
-
Write the prompt so it produces the same shape of output every time. Deterministic and narrow beats clever:
kiro-cli chat --no-interactive --trust-tools=read,grep \ "Review the staged diff for missing error handling. List findings only." -
Name the tool categories the job needs with
--trust-tools. A review job needs read access, not write or shell.--trust-all-toolsexists; treat it the way you would treat running a script as root. -
Add
--require-mcp-startupwhen the prompt depends on an MCP server. Without it, a pipeline can wait on a server that will never answer. -
Pin the persona. Run as a restricted custom agent with
--agent, so the tool ceiling lives in a reviewed file rather than in a shell line somebody may edit. See Create a custom agent. -
Add the step to your pipeline. Only the Kiro-specific lines below are verified commands and flags; the rest is ordinary GitHub Actions structure, shown as an example.
Example:
.github/workflows/review.yml# Example skeleton. The Kiro-specific parts are the env var and the # kiro-cli command; adapt the rest to your own pipeline. jobs: review: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Install Kiro CLI run: curl -fsSL https://cli.kiro.dev/install | bash - name: Review the diff env: KIRO_API_KEY: ${{ secrets.KIRO_API_KEY }} run: | kiro-cli chat --no-interactive \ --trust-tools=read,grep \ --require-mcp-startup \ "Review the diff on this branch for missing error handling." -
Set a budget expectation. Every prompt consumes credits, and an unattended loop spends them without anyone watching.
Check it worked
Run the job on a branch with a known problem and confirm the finding appears in the log. Then run it on a clean branch and confirm the output is short. The second run matters more: a job that always reports something is noise, and the team will stop reading it.
Common problems
- Authentication fails.
KIRO_API_KEYis not set in the job’s environment, or it is set on the wrong step. Environment variables do not carry across steps unless you set them at job level. - The run hangs. An MCP server is not connecting. Add
--require-mcp-startup. - The job asks for approval and times out. The prompt needed a tool category you did not trust. Add the category, or narrow the prompt.
- Output varies run to run. The prompt is too open. Ask for a fixed shape, such as a list of findings with file and line.
- Credits disappear. Something runs on every push. Restrict the trigger, or run the job on a schedule.
Related
- Kiro CLI Guide covers the interactive commands and the headless flags.
- Create a custom agent gives the job a reviewed ceiling.
- Set up permissions.yaml is the deeper guardrail.
Frequently asked questions
Can I run Kiro CLI in CI?
Yes. Kiro CLI supports headless operation: kiro-cli chat --no-interactive "your prompt" runs the prompt and exits. Authentication comes from the KIRO_API_KEY environment variable, supplied from your CI secret store.
How does Kiro CLI authenticate without a browser?
Through the KIRO_API_KEY environment variable. The interactive install flow finishes with a browser sign-in, but headless runs read the key from the environment instead.
How do I stop a headless run asking for tool approval?
Pass --trust-tools with the categories the job needs, for example --trust-tools=read,grep. Pre-approve the smallest set that works. --trust-all-tools exists but removes every guardrail from an unattended run.
☰ Chapter summary
- kiro-cli chat --no-interactive "prompt" takes the prompt as an argument and exits when done.
- Authentication in headless mode comes from the KIRO_API_KEY environment variable.
- --trust-tools=<categories> pre-approves only the categories you name; --trust-all-tools exists and deserves suspicion.
- --require-mcp-startup fails the run fast instead of hanging when an MCP server cannot connect.
- Run headless jobs as a restricted custom agent and watch the credit spend, because nobody is watching the loop.
All chapter summaries are collected on the revision page.
Related chapters
- Hands-onKiro CLI GuideInstall kiro-cli, drive sessions with slash commands, manage agents and context, and take the agent into scripts and CI.
- RecipesCreate a Custom AgentCreate a Kiro custom agent as a Markdown file in .kiro/agents/, set its tools field, and switch to it mid-session or with kiro-cli --agent.
- RecipesSet Up permissions.yamlControl what Kiro's agent may do with permissions.yaml: the capability list, the deny over ask over allow order, match and exclude globs, and the six scopes.
- RecipesAdd an MCP ServerAdd an MCP server to .kiro/settings/mcp.json or the global file, understand agent, project, and global precedence, and keep autoApprove empty.
- Hands-onAdvanced TutorialA production-shaped workflow that combines specs, steering, hooks, MCP, custom agents, and skills, written for engineers who already know the basics.