# Headless Mode

> The Headless Mode is a way of running a coding agent non-interactively from scripts or CI pipelines.

## How do I run an AI coding agent in CI?

The mode where an agent runs from the command line with a prompt and without an interactive interface, returning text or JSON. Used in CI/CD to fix lint errors, update docs or review pull requests automatically.

- Topic: Agentic Coding
- Type: concept

## Example

Wrong:

```bash
agent --prompt "Fix the failing tests" --allow-all-tools
```

Right:

```bash
agent --prompt "Fix the failing tests" \
  --allowed-tools "Read,Edit,Bash(npm test)" \
  --max-turns 15 \
  --output-format json > result.json
```

Listing allowed tools, capping turns and writing JSON makes the CI run safe, bounded and easy to parse.

## Common mistakes

- Running headless with all permissions on pull requests from forks, exposing secrets to injected prompts.

## Key points

- Allowed tools and commands are listed explicitly, because nobody can approve prompts in CI.
- API keys come from CI secrets, not from files committed to the repository.
- The run has a timeout or step limit, and output is in a parseable format such as JSON.

## Interview questions

### Is it safe to run an AI agent on pull requests from forks?

Only with no secrets and read-only tools. Fork pull requests can contain injected instructions, so never give that job write tokens or deploy access.

### How do I pass an API key to an agent in CI?

Store it as a CI secret and expose it as an environment variable for that job only. Never commit it to the repository or print it in logs.

### What is headless mode used for in CI?

Common uses are fixing lint errors, updating docs, triaging issues and reviewing pull requests, with results posted as comments or commits.

## Related cards

- [CI / CD](https://wonderium.dev/processes/ci-cd.md)
- [Agent Permissions](https://wonderium.dev/ai/agent-permissions.md)
- [Coding Agent](https://wonderium.dev/ai/coding-agent.md)
- [CLI](https://wonderium.dev/engineering/cli.md)

---

- Level: [Artificial Intelligence](https://wonderium.dev/ai.md)
- HTML version: https://wonderium.dev/ai/headless-mode
- Last updated: 2026-11-25
