|
| 1 | +--- |
| 2 | +title: Use Depot CI in coding agent loops |
| 3 | +ogTitle: How to use Depot CI CLI commands for coding agent loops |
| 4 | +description: Learn how to get your coding agent iterating locally with Depot CI. |
| 5 | +--- |
| 6 | + |
| 7 | +Depot CI is built for programmatic use, so it's a natural fit for AI coding agents. Instead of the usual push-wait-guess cycle, an agent can run CI locally, read the failure, fix the code, and rerun, all in a closed loop from your terminal. |
| 8 | + |
| 9 | +This guide provides an example of how to set up that loop. The guide covers Claude Code and Cursor, but the pattern works for any agent with shell access. |
| 10 | + |
| 11 | +## The agent loop |
| 12 | + |
| 13 | +You're working with an agent on a task, and you want to make sure CI passes before moving on or pushing your changes. |
| 14 | + |
| 15 | +No human needs to approve each step. You tell the agent to fix CI, and the agent iterates until it's done. |
| 16 | + |
| 17 | + |
| 21 | + |
| 22 | +For a raw narrative version of this pattern, see the blog post [The End of push-wait-guess CI](/blog/the-end-of-push-wait-guess-ci). |
| 23 | + |
| 24 | +## Why the CLI works well for agents |
| 25 | + |
| 26 | +Most coding agents already have a shell. The Depot CLI gives them CI without any HTTP plumbing. `depot ci run` tests workflows against your local working tree without requiring a commit or push. That's what makes the agent loop work: the agent can edit code and rerun CI in a tight loop without polluting the git history or waiting on long-running CI in GitHub. |
| 27 | + |
| 28 | +- `depot ci run` starts a run against your local working tree. Use `--job` to scope to specific jobs for faster iteration. The CLI resolves job dependencies automatically. |
| 29 | +- `depot ci status` shows the full run hierarchy, workflows, jobs, and attempts with their statuses. |
| 30 | +- `depot ci logs` fetches the log output for a failed job so the agent can read the error and fix it. |
| 31 | +- `depot ci ssh` connects directly to a running sandbox via the Depot API, giving you (or the agent) an interactive shell on the runner. To keep a sandbox alive at the right moment, use `depot ci run --ssh-after-step <n>` to inject a tmate debug pause after a specific step, then connect with `depot ci ssh` or the tmate connection string from the logs. |
| 32 | + |
| 33 | +## Prerequisites |
| 34 | + |
| 35 | +- Complete the Depot CI [quickstart](/docs/ci/quickstart). |
| 36 | +- Run `depot login` or set `DEPOT_TOKEN` so the agent can authenticate. |
| 37 | +- An AI coding agent with shell access (such as Claude Code or Cursor). |
| 38 | + |
| 39 | +## Install the Depot skills |
| 40 | + |
| 41 | +Install [Depot skills](https://github.com/depot/skills) to teach your agent how to get started with Depot and use all the Depot CLI commands for Depot CI. |
| 42 | + |
| 43 | +To install Depot skills with [skills.sh](https://skills.sh/), run `npx skills add depot/skills`. |
| 44 | + |
| 45 | +## Set up the fix CI loop command |
| 46 | + |
| 47 | +With the skills installed, create a command that tells the agent to use them, defines the loop, and sets the boundaries for what the agent can do autonomously. |
| 48 | + |
| 49 | +The example command for this guide is `/fix-ci`. |
| 50 | + |
| 51 | +Add a markdown file that defines the command to your repo. For example, in `.claude/commands/` or `.cursor/commands/`. |
| 52 | + |
| 53 | +Example `fix-ci.md`: |
| 54 | + |
| 55 | +```markdown |
| 56 | +Fix a Depot CI workflow, run, or job until it is green. |
| 57 | + |
| 58 | +### Before you start |
| 59 | + |
| 60 | +Invoke the `depot-ci` skill to load the full CLI reference. Then drive the debug loop. |
| 61 | + |
| 62 | +### Inputs |
| 63 | + |
| 64 | +Accept any of: |
| 65 | + |
| 66 | +- a workflow path (for example, `.depot/workflows/ci.yml`) |
| 67 | +- a run ID, job ID, or attempt ID |
| 68 | +- a target job name (for example, `build`) |
| 69 | +- a natural-language goal (for example, "make the test job pass") |
| 70 | + |
| 71 | +If the request is ambiguous, ask for the narrowest useful target. |
| 72 | + |
| 73 | +### The Loop |
| 74 | + |
| 75 | +1. **Run** the workflow against local changes, scoped to the smallest useful job. |
| 76 | +2. **Check status** and **read logs** for failed jobs. |
| 77 | +3. If logs aren't enough, connect to the running sandbox with **`depot ci ssh`**, or **rerun with `--ssh-after-step`** to pause at a specific step first. |
| 78 | +4. **Fix locally** based on what you found. |
| 79 | +5. **Rerun.** Repeat until green. |
| 80 | + |
| 81 | +### Autonomy |
| 82 | + |
| 83 | +The agent may: run workflows, inspect status/logs, SSH into runners, edit local files, and rerun until green. |
| 84 | + |
| 85 | +Ask before: changing secrets or vars, altering deploy or release behavior, opening a PR, or large refactors beyond the immediate fix. |
| 86 | + |
| 87 | +### When done, report |
| 88 | + |
| 89 | +- what was targeted |
| 90 | +- what was wrong |
| 91 | +- what changed |
| 92 | +- proof of green (or the exact remaining blocker) |
| 93 | +``` |
| 94 | + |
| 95 | +The key ingredients are the same for any agent: install the skill so the agent has the CLI reference, then give it a command or prompt that describes the run-status-logs-ssh loop and the autonomy boundaries. |
| 96 | + |
| 97 | +## Give the agent permission to run the loop |
| 98 | + |
| 99 | +For the agent to iterate autonomously, it needs permission to run `depot` commands without prompting. How you configure permissions depends on your agent. Here are some examples. |
| 100 | + |
| 101 | +### Claude Code permissions |
| 102 | + |
| 103 | +Add a permission rule to `.claude/settings.json` to allow any Depot command: |
| 104 | + |
| 105 | +```json |
| 106 | +{ |
| 107 | + "permissions": { |
| 108 | + "allow": ["Bash(depot *)"] |
| 109 | + } |
| 110 | +} |
| 111 | +``` |
| 112 | + |
| 113 | +### Cursor permissions |
| 114 | + |
| 115 | +Add a permission rule to `<project>/.cursor/cli.json` to allow any Depot command: |
| 116 | + |
| 117 | +```json |
| 118 | +{ |
| 119 | + "permissions": { |
| 120 | + "allow": ["Shell(depot)"] |
| 121 | + } |
| 122 | +} |
| 123 | +``` |
| 124 | + |
| 125 | +## Run the agent loop |
| 126 | + |
| 127 | +Type `/fix-ci .depot/workflows/ci.yml` (for example) in your agent chat and watch the agent take over. You can adjust your custom command using the tips in the following section. |
| 128 | + |
| 129 | +## Tips for customizing your agent loop |
| 130 | + |
| 131 | +### Iteration limits |
| 132 | + |
| 133 | +Cap the number of CI attempts so the agent doesn't loop forever on a fundamentally broken build. Three to five attempts is a reasonable default. |
| 134 | + |
| 135 | +### Log truncation |
| 136 | + |
| 137 | +CI logs can be long. If your agent has a limited context window, truncate logs to the last N lines or extract just the error output. Most failures surface near the end of the log. |
| 138 | + |
| 139 | +### Polling |
| 140 | + |
| 141 | +`depot ci status` returns immediately. It doesn't block until the run finishes. Agents will naturally poll by calling the status command in a loop. This works fine in practice. |
| 142 | + |
| 143 | +### Human approval gates |
| 144 | + |
| 145 | +If the agent shouldn't take certain actions autonomously, configure your agent's permission model to require approval for those commands. The `/fix-ci` command definition in the example includes suggested boundaries: the agent can run workflows, read logs, SSH in, and edit code, but should ask before changing secrets, deploying, or opening PRs. |
| 146 | + |
| 147 | +### Untracked files aren't patched |
| 148 | + |
| 149 | +`depot ci run` only includes tracked files in the local patch. If you've added a new file, use `git add` before running the agent, or add that step to your agent loop. |
| 150 | + |
| 151 | +## What's next |
| 152 | + |
| 153 | +The pattern in this guide is one way to implement a coding agent loop that uses Depot CI to iterate locally. Experiment with skills or sub agents or a mixture of these to create patterns that work for you. You can create more custom commands for managing or monitoring workflows with Depot CI. Learn more about the [Depot CI CLI commands](/docs/cli/reference/depot-ci) that your agents can use. |
0 commit comments