Agent workflows
How to Build an App With AI Without Burning Your Token Budget
Build an app with AI while managing token use and context: scope tasks, save checkpoints and verify each result.

Try the working reading-list example ↗
- Scope
- Build
- Check
- Record
Long app-building sessions can spend their context on repeated file reads, verbose logs, and decisions that never make it into the next session. The practical goal is not to use the fewest tokens on a single prompt: it is to finish the app correctly with less repeated work. Start with one small feature, a clear acceptance check, and a record of what was actually verified.
A context window and a usage allowance are different limits. Context is the information a model can consider during a request; an account or API budget controls what you can consume over time. A fresh session can reduce irrelevant history, but it does not necessarily reset a subscription allowance or make the work free. Check your provider’s current usage screen and pricing rather than assuming a fixed token conversion.
1. Define one vertical slice
For a reading-list app, choose a small outcome: add one valid link, reload the page, and see the link again. Write down the accepted inputs, expected result, and what is outside scope. Ask the agent to inspect only the files needed for that slice, propose a short approach, implement it, and run a focused check. Keep the full user journey in mind, but do not ask for ten unrelated integrations in the same turn.
A narrow task is not permission to skip accessibility or error handling. Include the relevant requirements in the slice: the form must have labels, invalid URLs need a clear message, and keyboard users must be able to submit it. A focused task with concrete checks usually creates a better stopping point than an instruction to keep working until the whole product is perfect.
2. Send pointers, not the entire repository
Give the agent the relevant file paths, the observed error, and the command that reproduces it. Let the tool read the necessary sections. Anthropic notes that attaching a file with the @ prefix can inject the full file into context; a plain path lets the agent choose what to read. Behavior varies by product and version, so verify your tool’s current documentation. Do not paste credentials or customer data into a prompt.
For example: “The submit button is in src/ReadingList.tsx. Saving a valid URL fails with the attached error. Inspect the handler and its storage adapter; add a regression test for the failure and run it.” This gives a reproducible target without embedding every file, lockfile, and old conversation. If the first inspection shows another file is necessary, allow the agent to follow the evidence.
3. Control logs and retries
Large build logs consume context and can bury the first useful error. Save full output to a local file and inspect a bounded excerpt around the failure. Preserve the exit code: a quiet log is not proof of success. For a long process, record its command and final result rather than starting another copy just because it has not returned immediately.
Set a retry budget for tool calls and tests. After repeated failures, have the agent state what changed and what evidence would distinguish the likely causes. Changing the same configuration repeatedly without a hypothesis consumes tokens and can break working behavior. Do not delete tests or weaken assertions simply to produce a green result.
4. Checkpoint before the conversation becomes crowded
Write a compact handoff containing the original outcome, constraints, files changed, commands run, actual results, outstanding failures, and the next specific action. Distinguish “implemented” from “verified.” Include the current revision where available and identify running processes by command and ID. Never put secrets or private customer data in a checkpoint.
Start a fresh session when the current one is dominated by stale investigation or when the product’s context tools indicate it would help. Ask the next agent to read the checkpoint and inspect the current files before continuing. A summary can omit details, so verify key assumptions against the repository. Some tools offer compaction or memory features; their behavior and cost vary. Neither compaction nor a fresh session guarantees that no information was lost.
5. Measure a completed task, not a single response
Record the task, model and tool version, usage shown by the provider, completion result, and whether human intervention was needed. API billing, cached input, subscription usage and context-window occupancy are different measurements. Compare like with like: use the same task and acceptance criteria, and count the retries and review effort that produced the final result. If a provider does not expose a figure, mark it unknown.
A shorter response can be more expensive if it causes a broken implementation and several follow-up sessions. A larger model may cost more per request yet finish a difficult task with fewer attempts; the opposite can also happen. Choose the smallest suitable approach based on actual outcomes and current provider pricing, not a promise that one model always saves money.
6. Verify the finished slice
Run the focused regression test, then exercise the feature as a user: add a link, reload, check it persists, and verify the invalid-input message. Review the code changes and any new dependencies. Keep evidence of the final command and exit status. A model’s statement that it is done is not a substitute for checking the artifact.
For a larger project, repeat the cycle for the next independently testable slice. Keep a short project-level checklist so the agent does not mistake the completed slice for the whole product. Before release, run the checks required for the complete app and verify the deployed version. This process manages context and rework; it cannot promise a particular token saving or eliminate model mistakes.
7. Build a prompt that survives a handoff
A useful prompt has four parts: the user-visible outcome, the boundaries, the files or symptoms that matter, and the checks that prove success. For the reading-list slice, write: “Add URL validation to the existing form. Accept HTTP and HTTPS addresses, display an accessible error for other protocols, and preserve existing saved entries. Inspect the current form and storage code first. Run the relevant checks and report the command and exit status.” Adapt the paths and commands after inspecting your own project.
The boundaries prevent a routine fix from expanding into an unrequested rewrite. The acceptance criteria keep the final report tied to behavior. Ask for a brief checkpoint if the task cannot be finished, but do not require a long plan after every single command. A short, specific request reduces ambiguity; the actual usage still depends on the tool, model, repository, and number of iterations.
8. Compare two ways to investigate a failure
Imagine an app fails when a saved URL is opened. One approach is to paste every source file and a long transcript into the conversation, then ask the model to guess. A more bounded approach is to provide the error, a minimal saved record without private data, and the location of the link-rendering code. Ask the agent to follow the data from storage to the rendered anchor and identify the first incorrect value.
If the issue cannot be reproduced, preserve the uncertainty. The agent can inspect the code and suggest a hypothesis, but it should not claim the browser behavior is fixed until a relevant check runs. If a new test fails because a dependency is missing, that is a setup failure, not proof that the assertion detects the original bug. Compare the same inputs before and after the change and record which environment you used.
9. Separate a long task into useful sessions
A session boundary is most useful after a coherent slice: the behavior exists, the diff is understood, and a focused check has a final result. At that point, capture the remaining work and any unresolved problems in a few lines. Starting a fresh session halfway through an unrecorded migration can increase work because the next agent must reconstruct what happened. The goal is not a strict timer or a fixed number of messages; it is a handoff with enough evidence to resume safely.
A practical handoff might say: “Goal: persist reading-list entries. Changed: form validation in src/ReadingList.tsx; storage adapter unchanged. Verified: validation test passed with exit 0. Not checked: persistence after browser reload. Next: reproduce the reload path and inspect storage.” Replace these illustrative results with your own actual files and outputs. Include the working revision where your project has one, and clearly identify any process that is still running.
10. Understand what a summary can lose
Compaction can preserve the broad goal while omitting a detail such as a mobile layout constraint, a failed release check, or a file the user asked not to change. Before relying on a compacted conversation, compare the summary with the original acceptance criteria and the repository. If a tool provides custom instructions for compaction, identify the constraints and decisions that must survive, while leaving out irrelevant logs.
Do not assume an automatically generated summary is a verified audit. Ask the agent to inspect the file and rerun a focused check if the result matters. Preserve exact errors or a link to a local log when paraphrasing would remove the evidence. A useful checkpoint should be short enough to read, but complete enough that another person can tell what is done, what was checked, and what remains unknown.
11. Handle tests and logs without wasting the signal
During implementation, start with the most relevant test or a small reproduction. Once the focused check passes, run the wider checks appropriate to the change. Do not use a narrow test to claim the whole app was checked, and do not keep rerunning an expensive full suite after every unchanged line. If a check fails, inspect the failure before changing the implementation or the test.
A useful log workflow keeps the full output in a local file and shows only the lines needed to diagnose the issue. The terminal command should preserve the process exit status. Be careful with pipelines that can return the status of a filtering command instead of the test itself. If the tool times out, find out whether the process is still running and inspect its artifacts before launching a duplicate.
12. Use multiple agents only for separable work
Parallel agents can help when tasks have clear ownership: for example, one investigates a failing form test while another reviews an unrelated accessibility issue. But each agent may read its own instructions and files, which can increase total usage. Assign distinct deliverables, avoid asking several agents to edit the same file, and reconcile their results against the original task. Do not assume a subagent shares all the main session’s context.
For a small bug, a single focused agent may be cheaper and easier to review. For a larger change, the right comparison includes coordination, duplicated investigation, and integration work. Ask each worker for evidence and unfinished items rather than a confident summary alone. If a task cannot be cleanly separated, serial work is often easier to verify.
13. Treat model choice as an experiment
You can try a smaller or faster model for a contained task, then use a stronger model when the work genuinely requires it. Keep the same task, repository revision, and acceptance criteria when comparing approaches. Save the actual usage figures the provider exposes and count manual corrections. One successful run cannot establish a reliable ranking, and an account-level usage indicator may not be comparable to an API invoice.
A meaningful decision balances cost per completed task against correctness, review time, and risk. If a cheaper attempt repeatedly breaks the same feature, the apparent savings can disappear. If the task needs sensitive credentials or writes to external systems, define access and review boundaries independently of the model selected.
14. A practical pre-release checklist
Before calling the slice done, check the requested behavior in the actual application, not only in a generated explanation. Confirm the relevant test has a final result, inspect the diff for unrelated edits, and check that errors are understandable. For persistent data, test a reload. For a responsive interface, check an appropriate small viewport and keyboard interaction. State separately which checks you could not run.
At release, follow the project’s existing gate and verify the deployed artifact where access is available. Keep the previous version available according to the project’s rollback process. Record the release URL and the checks that actually completed. This small record makes the next session cheaper to resume and makes it easier to spot whether a future problem belongs to the code, environment, or deployment.
Sources and next steps
Read Anthropic’s session management guidance and usage and limits documentation. For a deeper handoff checklist, see how to recover from agent context loss. The reading-list example linked on this site is a small local demonstration, not a benchmark of an AI model.