AI Agents in the Terminal: How Agentic Coding Tools Work

How terminal-based AI coding agents work: the plan-act-observe loop, tools for files and shell, permissions, sandboxing and instructions files.

Published November 27, 2026

Agentic coding tools that run in your terminal take a different approach from editor autocomplete. You describe a goal, and the agent explores the repository, edits files, runs commands such as your test suite, reads the output and keeps going until the task is done or it needs your input. Understanding the loop behind them helps you use them safely and get much better results.

The concept

At the core is a language model that can call tools. Typical tools include reading and searching files, editing files, running shell commands, and sometimes browsing documentation or calling external services. The model decides which tool to call, sees the result, and decides the next step. This plan-act-observe loop repeats, often dozens of times, for a single task.

Because the agent runs real commands in your environment, permissions matter. Good tools ask before running commands or editing files unless you have allowed them, support allow-lists for safe commands, and can run in sandboxes or containers. Your repository's state is the safety net: start from a clean git working tree so every change is visible in a diff and easy to revert.

The plan-act-observe loop

  1. Read the goal and project instructions (CLAUDE.md, AGENTS.md, README)
  2. Explore: search the codebase, read relevant files and tests
  3. Plan: decide which files to change and how to verify
  4. Act: edit files, run commands (with permission)
  5. Observe: read test/lint/build output, fix and repeat
  6. Report: summarise changes, show the diff, flag open questions
The agent loop for a typical coding task.

A real loop

YouAgentTools (files, shell)"fix the failing checkout test"run test suite1 failure: expected 1999, got 2000read checkout.ts, search roundingedit rounding logicrerun testsall passingdiff + explanation
A small task showing the observe-and-iterate pattern.

Safety controls

ControlWhy it matters
Permission prompts / allow-listsYou decide which commands and edits run automatically
Clean git state + branchesEvery change reviewable and revertible
Sandboxes / containers / worktreesLimit blast radius of commands
Project instructions fileConventions, commands, things never to do
No production credentials in the environmentAn agent cannot leak or misuse what it cannot access
Human review before mergeFinal accountability stays with people

Writing a good instructions file

Agents start each session without memory of your project. A short instructions file in the repo root gives them the essentials: how to build and test, code style, architecture notes, and rules such as "never edit generated files" or "use the SafeHttpClient for outbound requests". Keep it concise and current; it is effectively onboarding documentation for both agents and new teammates.

# AGENTS.md / CLAUDE.md
## Commands
- Install: npm ci   - Test: npm test   - Lint: npm run lint
## Architecture
- src/modules/<name>/ — each module exposes only index.ts; never import internals across modules
## Rules
- Do not modify migrations that have shipped; add a new one
- All money values are integers in paise

Practical examples

Effective task prompts

Specific, bounded, verifiable.

Weak:   "Improve the API."
Strong: "In src/modules/orders, add input validation for POST /orders using the existing zod
         schemas pattern (see users module). Return 422 with field errors. Add tests for missing
         customer_id and negative quantities. Run npm test."

Work on a separate branch or worktree

Isolate the agent's changes from your own work in progress.

git switch -c agent/orders-validation
# or a separate working directory for parallel tasks
git worktree add ../app-orders-validation -b agent/orders-validation

Review the result like any PR

Read the diff, run tests yourself, check for unintended changes.

git diff --stat main...agent/orders-validation
git diff main...agent/orders-validation -- src/
npm test

Common mistakes

  • Running an agent with broad permissions in a directory that contains production secrets.
  • Starting from a dirty working tree, making it hard to tell what the agent changed.
  • Vague goals with no way to verify success.
  • Skipping review because "the tests pass"; tests may be incomplete or the agent may have changed them.
  • Letting one long session sprawl across unrelated tasks instead of focused tasks.

Key takeaways

  • Terminal agents run a plan-act-observe loop with file and shell tools.
  • Permissions, sandboxes and clean git state keep them safe.
  • An instructions file is the highest-leverage setup step.
  • Give focused, verifiable tasks and review every diff.

FAQ

Can agents work on several tasks in parallel?

Yes, many teams run separate sessions in separate git worktrees or containers, each on its own branch, then review the resulting PRs.

Do agents remember previous sessions?

Generally not unless the tool has a memory feature. Repository instructions files and good commit history provide continuity.

Should agents be allowed to push or deploy?

Most teams keep pushes to protected branches and deployments behind human approval, even when agents open pull requests.

More Tooling articles