AskHandle

AskHandle Blog

How to Do Things With a Coding Agent

June 11, 2026Katherine Holland3 min read

How to Do Things With a Coding Agent

A coding agent such as Cursor, Claude Code, or Codex can seem surprisingly sharp when it opens only a handful of files, spots the right place to change, and proposes a clean edit that fits the project. The trick is not that the agent has magically absorbed the whole codebase. It is using a mix of language model reasoning, search, file context, project signals, and edit tools to build just enough local knowledge to act with precision.

Why a Few Files Can Be Enough

Most code changes do not require the whole repository. A bug fix, feature tweak, or refactor often lives in a small cluster of related files. If the agent can find the entry point, the call chain, the tests, and the type definitions, it may have enough context to make a good change.

For example, if you ask an agent to fix a broken button label, it may only need:

  • The component file
  • A related style file
  • A test file
  • A constants or translation file
  • The error message or failing test output

Software projects are usually organized around patterns. Components live near their tests. API handlers call service functions. Models, schemas, and types often use names that point back to the feature. A coding agent can use these clues to narrow the search.

The agent is not reading randomly. It is trying to identify the smallest useful slice of the project.

How the Agent Finds the Right Files

A coding agent often starts with the user request and turns it into search terms. If you ask, “Fix the checkout discount calculation,” the agent may search for words like checkout, discount, coupon, total, or price.

It can also inspect file names. A file called CheckoutSummary.tsx or discountService.py is an obvious candidate. Once it opens one file, it looks at imports, function names, exported symbols, and nearby comments. Those details lead it to more files.

Common signals include:

  • Import statements
  • Function and class names
  • Type names
  • Test names
  • Error messages
  • Route names
  • Config entries
  • Package scripts
  • Directory structure

This creates a trail. The agent follows that trail until it has enough context to make a safe guess about where the change belongs.

The Role of Search and Symbols

Modern coding tools are not limited to plain text reading. Many can use search indexes, language server data, or symbol lookup. That means the agent may ask questions like:

  • Where is this function defined?
  • Where is this class used?
  • What imports this module?
  • Which tests mention this behavior?
  • What type does this value have?

Symbol search is much more useful than reading files from top to bottom. If the agent sees a function call named calculateDiscount, it can jump directly to its definition. If it sees a type named CartItem, it can find the source type. If a test fails inside applyPromoCode, it can search for that exact function.

This is one reason targeted edits can feel precise. The agent is not only predicting text. It is collecting structural clues from the codebase.

How the Model Uses Context

Once the agent has opened a few files, it feeds relevant snippets into a language model. The model sees the user request, the file contents, and sometimes tool output such as test errors, lint messages, or search results.

From there, the model performs pattern matching and reasoning. It looks at how the code is written, how nearby functions behave, and what style the project follows. If the project uses async functions, named exports, strict types, or a certain error-handling pattern, the agent tries to copy that style.

This is important. Good code edits are not only about solving the stated problem. They must fit the local codebase. A targeted edit works because the model can infer conventions from a small sample.

For example, after reading one service file and one test file, the agent may learn:

  • The project uses dependency injection
  • Errors are returned as objects, not thrown
  • Tests use factory helpers
  • Monetary values are stored in cents
  • Feature flags are checked before logic runs

Those small facts can prevent bad edits.

Why Agents Prefer Small Patches

A good coding agent usually tries to make the smallest change that solves the problem. Large rewrites create more risk. Small patches are easier to review, easier to test, and easier to roll back.

Targeted edits often follow this pattern:

  1. Identify the likely file.
  2. Locate the exact function or block.
  3. Change only the needed lines.
  4. Update nearby tests if needed.
  5. Run or suggest a test.
  6. Show a diff.

This workflow mirrors how a careful developer works. The agent uses the local context to avoid touching unrelated code.

Small patches also help with model limits. A language model can only process a certain amount of text at once. If the agent fills that space with unrelated files, quality drops. Narrow context usually gives better output.

How Patch Generation Works

When the agent proposes an edit, it often does not rewrite the whole file. It creates a patch. A patch says, in effect, “replace this block with that block.”

This matters because code editing requires exact placement. The agent must preserve the rest of the file, keep formatting stable, and avoid accidental deletions.

A typical patch depends on anchors, such as:

  • A function signature
  • A nearby comment
  • An import block
  • A test case name
  • A unique line of code

The tool can then apply the change to the correct location. If the file has changed since the agent read it, the patch may fail, which is safer than applying the wrong edit.

Why Tests Make Agents More Accurate

Tests give coding agents a feedback loop. Without tests, the agent must rely on prediction. With tests, it can see whether the change worked.

A failing test output can point directly to the bug. A passing test can confirm that the edit did not break the checked behavior. Even when the agent cannot run tests itself, it can still read test files to learn expected behavior.

Tests often explain the project better than documentation. A test may show edge cases, input shapes, and expected outputs in a compact form. That helps the agent make edits with more confidence.

Where Coding Agents Still Struggle

Coding agents are useful, but they are not perfect. They can miss hidden behavior in files they did not read. They can assume a pattern is universal when it only applies in one area. They can make a change that passes a narrow test but breaks a broader workflow.

Common weak spots include:

  • Large cross-cutting refactors
  • Implicit runtime behavior
  • Complex build systems
  • Poorly named files
  • Missing tests
  • Generated code
  • State shared across distant modules
  • Business rules that live outside the code

The agent’s skill depends heavily on the quality of the context it gathers. If the request is vague or the repository is inconsistent, the agent may need more guidance.

How to Get Better Edits From a Coding Agent

You can improve results with better prompts and better project signals. Give the agent a clear goal, mention the bug or feature, and include any error output. If you know the relevant file, name it. If there is a test command, provide it.

A strong request might look like this:

Fix the discount rounding bug in checkout. The failing test is CheckoutSummary applies percentage coupons. Money should stay in cents until display. Please make the smallest change possible.

That tells the agent what to search, what rule matters, and how broad the edit should be.

You can also ask the agent to explain its plan before editing. This helps catch wrong assumptions early.

The Real Reason It Feels Smart

A coding agent can read a few files and offer targeted edits because most code has structure, names carry meaning, and local context is often enough. The agent combines search, symbol tracking, pattern recognition, patch tools, and test feedback to act like a focused developer working through a bug.

It does not need perfect knowledge of the whole codebase every time. It needs the right slice of context, a clear goal, and a way to verify the change. When those pieces line up, a few files can be enough to produce a useful, accurate edit.