esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • AI papersPages
  • Interview KitPages
  • Book a callContact
Let’s talk

I’ll build the agent for it.

Design a Code Assistant

How to design a code assistant that finds the right code, edits safely and stays fast and affordable, explained simply for your AI interview.

In short

A code assistant finds the few files that matter, asks a model for a change, checks it by running tests in a sandbox, and shows a diff that a person accepts. Context, speed, safety and cost decide the design.

11 min readAdvancedCommon · estimateFacts checked 27 November 2026

Say it out loud

Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.

A code assistant reads the parts of a codebase that matter, asks a model for a change, runs the tests in a locked sandbox, and shows a diff for a person to accept. The hard parts are picking the right code within a fixed context budget, keeping outside text from giving orders, and keeping answers fast and cheap. I'd start with simple search and a strict permission model, then measure it on real past bugs.

What is a code assistant, in plain words?

A code assistant is a program that reads a codebase, answers questions about it, and proposes changes that a developer then reviews. Three kinds are common. An inline one finishes the line you are typing, in well under a second. A chat one answers questions about the code. An agent takes a ticket, edits several files, runs the tests and reports back. A repo, short for repository, is all the code for one project.

Think of a new engineer on a payments team. They don't read all 900 files. They search for the refund code, open the files that call it, check the tests and send a small change for review. A code assistant does the same walk in seconds. It can also forget what it read if the file list is too long.

  • “Claude Code is an agentic coding tool that lives in your terminal, understands your codebase”

    Anthropic, Claude Code README

Two real examples are Claude Code from Anthropic and Codex CLI from OpenAI. Codex CLI runs on the developer's own computer.

Key words

Token
A small chunk of text, often part of a word, that a model reads and bills for.
Context window
The text a model can see in one call. It is limited, and every token costs money.
Diff
The before and after of a change, line by line, so a person can review it.
Sandbox
A locked box the tool runs in, so a bad command can't touch the rest of the machine.

How does it find the right code?

A repository is far too big for one prompt, and a bigger window only goes so far. Anthropic's engineers describe the trade-off this way:

  • “as the number of tokens in the context window increases, the model's ability to accurately recall information from that context decreases”

    Anthropic, context engineering guide

So treat context as a budget. A prebuilt map of function names and files is fast to read but can go stale. Search on demand reads the live code. Anthropic describes this "just in time" style as avoiding stale indexing, at the cost of slower runtime exploration.

Research favours retrieving the right code over more code. RepoCoder, a 2023 study, uses iterative retrieval and generation, and it improves on the in-file baseline by over 10% in all the settings it tested.

Position matters too. A 2023 study, Lost in the Middle, found that performance can degrade significantly when the relevant information moves within a long input. Performance is often highest at the beginning or end. That study used documents, not code, so treat the placement advice as a guide.

  1. 1

    Map the repo once

    Index the names of functions and classes, the files, and who calls what. Refresh the map when files change.

  2. 2

    Search for the task

    Match the ticket's words and error messages against files, and use meaning search where the words differ.

  3. 3

    Read only what matters

    Open the files the matches point to, plus their tests and recent edits.

  4. 4

    Pack to a fixed budget

    Fill a set number of tokens, strongest files at the ends, and leave out the rest.

Packing the right code into the prompt

The repo, 900 files

far too big for one prompt

Symbol map

functions, classes, who calls them

Search

text and meaning search, on demand

Pack to budget

8,000 tokens, most relevant first

Model prompt

strongest files at the ends

Dropped files

past the budget, lowest scores

  1. 1The map is built once and refreshed when files change.
  2. 2Search runs only when the task needs it.
  3. 3The map's best matches are packed in until the budget is full.
  4. 4The search's best matches are packed in the same way.
  5. 5The packed files go to the model, strongest at the ends.
  6. 6Files that don't fit are left out, not squeezed in.
The repo is too big to send whole. A map and a search find candidates, and the packer fills a fixed budget with the strongest files. The rest is dropped.

Take a made-up refund bug and a budget of 8,000 tokens. The packer keeps the three most relevant files, about 7,300 tokens, and drops the big legacy export, which alone would use more than half the budget.

How do edits get applied, and how do you keep it safe?

The model proposes a diff, and the tool applies it to a scratch branch, runs the tests and a lint check (a tool that flags messy or risky code), and shows the result. If the tests fail, the error goes back to the model. I'd cap it at three tries, which is my own design choice.

One change, from ticket to review

A bug ticket

refund total is off by a cent

Gather context

find code, tests, recent edits

Model

proposes a diff or a tool call

Tools in a sandbox

read files, run tests and lint

Diff for a person

accept, edit or reject

  1. 1The ticket goes in, and the assistant starts searching.
  2. 2The best matching code, tests and recent edits are packed in.
  3. 3The model asks to read a file or run the tests.
  4. 4The tool's result goes back so the model can try again.
  5. 5The diff and its test result go to a person.
A ticket goes in, and the model and its tools loop until the tests pass or the tries run out. A person then sees the diff. The one loop back is the model reading each tool result.

Assume the text in the repo can be hostile. A comment, a README or an issue title can carry an order, and the model may follow it. OWASP's 2026 list of LLM risks names a database row or an issue title as a way in for prompt injection.

In its October 2025 sandboxing post, Anthropic said Claude Code is read-only by default, and asks for permission before changes or commands. A sandbox gives fixed walls instead: filesystem isolation limits the tool to specific directories, and network isolation limits it to approved servers. In Anthropic's internal use, sandboxing cut permission prompts by 84%.

Keep secrets out of the packer. Passwords, keys and .env files (files that hold secrets) go on a deny list, and the model never holds keys. OWASP says to hold credentials and state-changing power in application code, not the model, with least privilege per operation.

How do you keep it fast, cheap and tested?

Each call costs money and time, so the design uses three levers: a small model for inline help, short context for it, and a cache for the stable part of the prompt. Anthropic's caching guide says prompt caching works by letting the API resume from specific prefixes in your prompts. So put the rules and the repo map first and the ticket last.

A design target I'd set, with made-up numbers: 95% of inline suggestions back in under a second, and a monthly cost cap per developer that alerts before it is reached.

Build an offline test set from your own past bugs, each with a known fix and its test. Replay each ticket, let the assistant try, and count how many fixes pass. Then track what happens after a merge: how often people accept the diff, how much they edit it first, and how often it is reverted within a week.

A passing test only shows the checks pass. The team still has to want the change. Log what was packed for each run too, since a better model can't fix a file it never saw.

What does the interviewer want to hear?

A strong answer covers

  • A plain picture: the model proposes, tools act, and a person approves.
  • Which kind of assistant it is, inline, chat or agent, and why the limits differ.
  • Context as a budget: map, search, read just in time, then pack.
  • Edits land in a branch, checked by tests in a sandbox.
  • Repo text treated as untrusted input, with a deny list for secrets.
  • Evaluation on past real bugs, plus speed and cost targets.

Common traps

  • Trap"Put the whole repo in the prompt."

    BetterA big window still loses detail. Retrieve the few files that matter and pack them to a budget.

  • Trap"Let the agent push straight to main."

    BetterEdits land in a branch, checks run in a sandbox, and a person merges.

  • Trap"A bigger model fixes it."

    BetterA stronger model can't use code that never reached the prompt, and it can't undo permissions you gave it.

Can you spot the risk?

Spot the risk

Which setting is the risky one for an agent on a payments repo?

Quick check

A developer reports a bug in a 900-file service. What should the packer send first?

Can you answer these from memory?

Flash cards · tap a card to flip it

1 / 6

What will they ask next?

  1. Q352Design a work copilot that never leaks data the user can't access.12 min
  2. Q353Design an LLM gateway.12 min
  3. Q356Design rate limiting.12 min
  4. Q357Scale to millions of users.13 min
  5. Q189How do coding agents work?13 min

Learn it in depth

Last updated on 27 November 2026

Building a coding assistant for your team's codebase?

I design and build AI products and agents, the interface and the system behind them, so a short call is the best next step. Tell me your stack, your repos and what must stay private.