Skip to content
86% off$349 $48.86code BF2026

Guides

What Is a Coding Agent? How AI Coding Agents Work

A coding agent is an AI model that reads, edits and runs your code in a loop. Learn how the loop works, what agents cost and how to run them safely.

ExplainerUpdated 11 min read

On this page

A coding agent is an AI model connected to tools that let it read your files, edit them, run commands and check the results. It repeats that loop until the task is done or it needs you. Autocomplete suggests the next few lines. An agent takes a goal, such as "fix the flaky login test," and works through it: it searches the code, makes a change, runs the tests, reads the failures and tries again.

The model itself only produces text. Everything it "does" goes through the agent program around it. That program turns the model's requests into real file reads, edits and shell commands, and it decides which of them need your OK. That split explains most of how agents behave, what they cost and where the risks come from.

How a coding agent works: tools, turns and context

Tools

The agent program gives the model a fixed set of tools. On each step the model either answers in plain text or asks for a tool call. The program runs the tool, adds the output to the conversation and asks the model what to do next.

As a concrete example, here is the full tool list of the native agent we build into Sledbot. Other agents name their tools differently, but reading, searching, editing and running commands are the core of every coding agent.

ToolWhat it does
read_fileReads a file (up to 2,000 lines per call)
list, glob, grepLists folders, finds files by pattern, searches text
edit_fileChanges a file
bashRuns a shell command in a visible terminal; times out after 120 s by default, 600 s at most
git_status, git_diffShows what changed
web_fetchDownloads a web page with an HTTP GET (up to 100 KB)
todoKeeps a task list for the current job
memory_appendSaves a fact for later threads
sled_spawn, sled_send, sled_wait, sled_readStarts other agents, messages them, waits for them and reads their output
sled_approve, sled_notifyAsks you for approval, posts a notification

A run on "fix the flaky login test" might go like this:

  1. grep for the test name to find the file.
  2. read_file on the test and the code it calls.
  3. bash to run that test several times and see it fail.
  4. edit_file to change the code.
  5. bash to run the tests again.
  6. git_diff to check the change, then a written summary for you.

Every step is a separate tool call, and every result goes back to the model before it picks the next one. That is why an agent can catch its own mistakes: it sees real test output, not just its own guess.

Turns

A turn is one round of the model reading the conversation and responding, usually with one or more tool calls. Agent programs cap runs so an agent can't loop forever. Sledbot's native agent, for example, stops after 60 turns and waits for you ("Reached the turn limit (60). Send a message to continue."). It limits each model call to 16,384 output tokens and can also stop when a run reaches its dollar budget.

Many agents also have a read-only mode for planning. In Sledbot's Plan mode the agent can read and search files, view git status and diffs, fetch web pages, read other agents' terminals and keep a todo list, but it can't edit or run commands. Ask for a plan first, then switch to Build mode (all tools). A wrong approach is much cheaper to catch before any file changes.

Context

Context is everything the model sees on a given call: its instructions, your task, the files it has read and the command output it got back. It is measured in tokens, and each model has a maximum, its context window. Gemini CLI, for example, advertises access to a 1M token context window.

Long sessions fill that window. When it gets close, the agent program compacts the conversation, replacing older parts with a summary. Sledbot's native agent compacts at 75% of the window. Two practical effects follow:

  • Agents forget details in long sessions. After compaction, exact file contents and earlier decisions may be gone, so the agent re-reads files or repeats work. Smaller, focused tasks avoid this.
  • Long sessions cost more. Most model APIs keep no memory between calls, so the conversation is sent again on every turn. Prompt caching makes the repeated part cheaper, but a bloated context still adds up, in dollars on an API key or in used-up limits on a subscription.

Terminal, IDE and cloud agents

The same loop can run in three places. Examples are as of November 2026.

TypeWhere the loop runsExamplesGood atTrade-off
TerminalA CLI on your Mac or a serverClaude Code, Codex CLI, Gemini CLI, GitHub Copilot CLI, Cursor CLI, Goose, Crush, OpenCode, AiderWorks next to any editor, scriptable, runs over SSHReviewing diffs in a terminal is harder; the session ends when the terminal closes
IDEInside your editorClaude Code extension for VS Code (also Cursor and other VS Code forks), Cascade in Windsurf (now renamed Devin Desktop), Zed with external agents, Copilot in JetBrains IDEsInline diffs and review where you already read codeUsually lives as long as the editor window
CloudA remote machine run by the vendorCodex cloud (codex apply pulls its diff into your local checkout), Amp's "orbs", Cursor cloud agents, Copilot in the cloudKeeps working while your Mac is closedYour code runs on someone else's machine; usage is metered (Amp bills orbs by the hour)

The lines blur. Goose ships as a CLI and a desktop app, and editors such as Zed and JetBrains IDEs can drive it as an agent. JetBrains IDEs can hand tasks to a local Copilot CLI agent (in public preview).

A fourth group sits on top of terminal agents: workspaces that run several of them side by side, such as Claude Squad (a tmux and git worktree TUI), Conductor and Sledbot. They don't replace the agent. They manage many copies of it. See how to run multiple Claude Code agents in parallel.

How agents ask for permission

Because the agent program runs every tool call, it can stop and ask first. Agents offer roughly three levels:

  • Ask every time. Each command or edit waits for a yes. Safe, but you get interrupted constantly.
  • Rules. Low-risk actions (reading files, running tests) go ahead and risky ones ask. Copilot CLI, for example, lets you configure trusted directories, tool access, and file and URL permissions.
  • Skip everything. Every action runs unattended. It's fast, and nothing stops a bad command. Before you try it, read a safer alternative to --dangerously-skip-permissions.

Rules work best when they target actions that are hard to undo or that leave your machine. Sledbot's built-in rules ask first for the list below, and it makes a good checklist for any agent setup:

  • git push to a protected branch (main, master, release branches, production)
  • merging a pull request
  • deploy commands (vercel --prod, fly deploy, kubectl apply, terraform apply, helm and similar)
  • publishing packages (npm publish, cargo publish, docker push and similar)
  • rm -r outside the agent's worktree
  • file writes outside the worktree (temp folders excepted)
  • anything run with sudo
  • cloud CLI commands that change things, such as aws … delete or gcloud … deploy
  • curl or wget POST, PUT, PATCH or DELETE to anything other than localhost, and any call to a production host

When an "allow" rule and an "ask" rule both match, the safer design is for "ask" to win. Sledbot's own "Ask first" rules work that way.

There is also a difference between blocking and watching. An agent program that runs a check before each tool call can refuse an action outright. Claude Code supports this through hooks that fire before a tool runs, and Sledbot uses one to hold Claude Code's risky actions until you answer. With agents that only show their own on-screen prompts, an outside tool can mirror and answer those prompts, but it can't stop an action the agent decides to run without asking. Which kind you have decides whether a rule is a real boundary or just a notification.

Claude Code session in Sledbot with a Needs you banner: Wants to run npm install stripe@17.4.0, with Deny and Allow once
Answer an approval right in the agent's session.

What it costs: subscriptions, API keys and local models

There are three ways to pay for the model behind an agent. Details below are as of November 2026.

Subscription login. You sign in to the agent with a plan you already have, and usage counts against that plan's limits.

  • Claude Code: in the Claude desktop app it's on the paid plans. The VS Code extension needs a Claude subscription, an Anthropic Console account or a third-party model provider.
  • Codex CLI: the CLI is free and open source (Apache 2.0). Usage comes from a ChatGPT plan or an OpenAI API key, and third-party guides describe rolling 5-hour usage limits on subscription plans.
  • GitHub Copilot CLI: GitHub's plans page says the Free plan supports the CLI and agent mode, with limited use. Paid plans are Pro $10/month, Pro+ $39/month and Max $100/month, and agent use draws on GitHub AI Credits.
  • Gemini CLI: free with a personal Google account, at 60 requests a minute and 1,000 a day according to its site. Third-party reports say Google is moving users to a new Antigravity CLI, so check its status before you build a workflow on it.

API keys. You pay the model provider per token. There's no plan window to wait out, but there's also no ceiling unless you set one, so set a spend limit at the provider.

Local models. Ollama and LM Studio run open models on your Mac for free. LM Studio needs Apple silicon and macOS 14 or later. Third-party sources cite roughly 4 GB of RAM for a 3B model and 8 GB for a 7B model. An agent can't work without tool calling, and not every model supports it, so test a model on a small task before you rely on it. See how to run a local AI coding agent on your Mac.

To see where the tokens go, look at the session logs Claude Code and Codex keep on disk. ccusage reads Claude Code's logs, and Sledbot's Insights reads Claude Code, Codex and OpenCode logs alongside its own agent. More in how to check Claude Code usage and limits.

Running agents safely: worktrees, approvals and review

The practical risks are three: agents stepping on each other's files, agents doing something you can't undo, and agent code you merge without reading.

Give each agent its own checkout

If two agents, or you and an agent, edit the same folder, changes collide and test runs mix both sets of edits. A git worktree gives each agent a separate checkout on its own branch while sharing one repository. This creates a second working copy in ../myapp-agent on a new branch, agent/fix-login:

bash
git worktree add -b agent/fix-login ../myapp-agent

Point the agent at that folder. To undo it, remove the worktree, then delete the branch once it's merged (-d refuses to delete an unmerged branch):

bash
git worktree remove ../myapp-agent
git branch -d agent/fix-login

One catch: a new worktree only contains tracked files. Git-ignored items such as .env and node_modules are missing, so the agent has to set them up before tests pass. In Sledbot you can list setup commands and files to copy in a per-repo .sledbot/config.json. Claude Code worktrees covers the details.

Keep risky actions behind approvals

Leave approvals on for everything in the checklist above, even if you allow edits and test runs freely. Keep production secrets out of the folders agents work in: an agent that can read files can read .env.

Review the diff, not the summary

An agent's summary describes what it meant to do. The diff shows what it did. Read git diff (or a per-hunk review view) before you commit, and have the agent run the tests rather than taking "all tests pass" on trust.

Where Sledbot fits

For one agent on one task you don't need extra software: a terminal agent in a worktree with approvals on is enough. Sledbot helps once you run several at once. It runs Claude Code, Codex CLI, Gemini CLI, GitHub Copilot CLI and other CLI agents in real terminals, and in a git repo it starts each task in its own worktree by default. Pending approvals and questions collect in one "Needs you" list, and a per-hunk Accept / Reject / Comment review comes before you merge. The agents keep running after you quit the app. Blocking works for Claude Code and Sledbot's own agent; other CLIs have their prompts mirrored and answered, not blocked. Sledbot is part of MacSuite; you can try it free for 7 days.

Getting started with your first coding agent

  1. Pick the agent that matches what you already pay for. A ChatGPT plan points to Codex CLI, a paid Claude plan to Claude Code, a Copilot plan to Copilot CLI. With no plan, try Gemini CLI's free tier or an open-source agent such as Goose or OpenCode with a local model. Best AI coding agents for Mac and best free and open-source coding agents compare them.
  2. Start in a git repository with everything committed. Then any change the agent makes to your files can be undone with git. Commands that reach outside the repo can't, which is what approvals are for.
  3. Give a small task with a clear check. "Make npm test pass for the login module" beats "improve the login code."
  4. Keep approvals on for your first sessions. Watch which commands it asks to run before you loosen any rules.
  5. Read the diff before you commit. Ask the agent about anything you don't understand.

If you use Claude Code, start with how to install Claude Code on a Mac.

FAQ

Is a coding agent the same as AI autocomplete?

No. Autocomplete predicts the next lines while you type. An agent takes a task, runs tools such as file edits and shell commands, and checks its own results over many steps.

Are coding agents autonomous?

Partly. Between check-ins an autonomous coding agent picks its own next step, but it can only use the tools and permissions its agent program gives it. It stops when it finishes, hits a limit or needs your approval.

Does an agent keep working if I close the terminal?

Usually not: closing the terminal ends the process. You need a terminal multiplexer, a cloud agent or an app that keeps sessions alive. See keep Claude Code running after you close the terminal.

Every app.
One purchase.