How I build with AI without wasting tokens or losing control
Fresh chats, small slices, handoff notes and a few safety habits keep my AI-assisted builds focused and under my control.
Glendon Cabrias 10 min read
On this page
On the project before this portfolio, my AI sessions kept going wrong in the same few ways.
A long session got compacted, and the agent kept editing from its stale summary instead of the file on disk. A broad recon prompt, the “go and look around” kind, looped for hours. A request to only plan, with no edits, tried to edit anyway, and the compaction that followed threw away the analysis I was waiting for.
I work with a local model that has a context window of about 64K tokens. That is not much room, and the easy habit is to keep one conversation open for the whole project and let it fill up.
So I changed the workflow. Every slice of work gets a fresh chat, and the project’s memory lives in documents instead of in the conversation. Each new chat starts from a short handoff message. Terminal scripts keep the edits fast, and a rule for reasoning effort keeps the work from getting wasteful.
This post covers that workflow and where it falls short. I have not measured how many tokens it saves, and I will say so where it matters.
One slice, one fresh chat
I start a fresh chat for every slice of work. A slice is one piece of the project with a short brief: what to build, a few steps, and a way to tell when it is done. For the coding agent I go smaller still, with a new task for every step inside the slice.
A conversation collects more than instructions. It also holds file contents, generated code, tool output, abandoned approaches and corrections. That feels handy at first, because the AI already knows what happened. Later, most of it has nothing to do with the task in front of me, and all of it is still sitting in the context.
There is research behind the worry. The paper Lost in the Middle: How Language Models Use Long Contexts found that models did best when the relevant information sat at the beginning or the end of a long input, and that performance dropped significantly when it sat in the middle. That does not make every long chat unreliable, and a fresh chat does not fix anything on its own. It does mean that more context is not automatically better context.
Cost is the second reason. Some coding tools resend the whole conversation with every new request. The article Models, usage, and limits in Claude Code says every previous message is sent again on each turn, and that prompt caching makes the later turns cheaper to bill without stopping them from taking up space in the context window. How a given tool bills for this varies, so I treat it as a reason to keep chats short and not as a number.
Sometimes a slice outgrows its chat. A revision turns into a design change, or I find that the planned approach cannot work with the current structure and something else has to happen first. When that happens I do not stretch the chat. I cut smaller slices, each with its own chat and goal: investigate, change the structure, then build the feature.
One more thing, and I will label it as an observation. Long sessions seem to use up my usage window faster. I have not isolated the cause, and the limits depend on the tool and the plan, so treat it as one person’s experience.
The documents are the memory, and I attach only part of them
A fresh chat only works if it can pick up where the last one stopped, so the project’s memory lives in documents. They cover the overview and goals, the technical stack, decisions with the reasons behind them, coding rules, the design, and the plan, with a brief and acceptance checks for each slice.
Then comes the habit that saves the most: I do not attach all of them. Each file has one job, and a short index page says which to read and in what order: the index, then the status file, then the brief for the current slice, then only what that brief lists.
A few things go into every chat:
- The status file. Where the project stands, what is done, what is unresolved and the exact next action. It is updated at the end of every slice, so it is never older than the last piece of work.
- The current brief. The steps and acceptance checks for this slice only, not the whole plan.
- The decisions file. Every locked decision with its reason, so a new chat does not reopen it.
- The rules. A small set that is always loaded.
Everything else shows up only when a slice calls for it. A layout slice gets the design document. A copy slice gets the written copy. A blog slice gets the two files on how I write and publish posts.
The numbers are why I am strict about it. Out of that 64K window, my always-loaded rules take roughly 2.5K tokens, the status file about 1K, the current step about 1K, and the files for the step another 4K to 10K. Those are my own estimates, not measurements, and they leave plenty of room. My old setup loaded around 50 KB of rules into every session, and it ate into the window before any work started.
The handoff carries what the documents cannot
At every slice boundary a handoff message gets written for the next chat, and that chat writes one for its successor. It does two jobs.
First, it lists the documents the next chat needs, and sometimes only a section of one. A long document may matter for a single numbered section, so the handoff names that section and I leave the rest out. Second, it holds what no document covers: the branch and the last commit, where the last work stopped, the exact next step, the open items, and the gotchas I ran into.
The chat can forget everything, as long as the documents and the handoff remember.
Documents describe how the project works. They do not reliably say that I stopped halfway through a step, that one check is still failing, or that the next slice should begin with a particular decision. The handoff does.
The handoff is written fresh at every boundary, so it is never older than the last slice, and it only has to cover what the status file cannot.
One line in every handoff tells the new chat to check the status file against the commit history before trusting it. Documents drift from the code. If the two disagree, I want to find out before the work starts, not after.
Write down what went wrong
When something goes wrong, I write it down where the next chat will read it. Four kinds of notes earn a place:
- Decisions. What I chose, why, and which alternatives I rejected, so a later chat does not suggest an option I already ruled out.
- Mistakes. What happened, what caused it, and what to do differently.
- Reusable skills. A pattern or a way of doing something that I expect to need again.
- Workflow changes. A better way to split tasks, word instructions or review generated code.
I do not save whole conversations. That would bring the long-context problem back in a new file.
A reusable skill can be a whole job. After my first blog post I wrote down how I publish one: a rules file for voice, structure, search and honesty, and a checklist file for the files, front matter, cover, figures and checks. Since then a new draft goes into a fresh chat with those two files and gets finalized against both, so I do not work the rules out again for each post.
A small real example: I once chained two commands with &&, and the first one counted matches with grep -c. It found none, printed 0 and exited with an error, so the chain stopped before my push. Nothing was lost, but the push did not happen. It is now a rule in my workflow file: never chain a count with &&, use a semicolon and read the number.
When a project ends I read through the notes and keep what will matter next time. That is how the next project starts with my habits instead of a blank page.
Spend the model, and the effort, where it pays
I do not send every task to the biggest model. A local model handles most of my everyday help. Cloud models, including free tiers, cover what it cannot: anything that needs fresh outside information, a second opinion on a design, or a review at the end of a slice.
I am not against paid plans. For steady, daily development a subscription can be worth it. I just do not want to depend on one to keep building, and so far this approach has been enough for me to finish real projects without paying for AI usage. With a paid plan the progress would simply be faster, because the daily limit is higher.
Reasoning effort follows the same logic. My default is medium, because finding a file or explaining a snippet does not need more, while hard debugging, an architecture choice or a task with many moving parts does. The page Reasoning models describes effort as how much the model thinks, notes that reasoning tokens are billed as output and take up space in the context window, and says the defaults depend on the model.
The part I am most particular about is when to switch to high. If I am asked to switch in the middle of an investigation, the switch is wasted: the model has not finished looking, so the high-effort answer is built on half the facts. I save high for steps like a new layout, a schema change or an art build, and my rule for the assistant is:
- Stay at medium while the investigation is still running.
- Settle everything the next step needs.
- Then ask me to switch, in a separate reply that holds only the heads-up and the step it is for.
- Do the build in the reply after I switch, and I go back to medium myself afterwards.
A reply that is still waiting on output I have to paste never asks for high. I would rather switch once with everything settled than twice with half the information. It does not guarantee a correct first try. It gives the model the right amount of thinking at the right moment.
Terminal scripts are fast, and they need a safety net
For mechanical edits I stopped asking an agent to click through files and started running a script from the terminal. An editing tool that matches exact text struggles with big moves, long blocks and whole-file rewrites. It fails, retries and burns context on every attempt, while a short Python script does the same job in one run. If an agent fails the same edit twice, I stop it and switch to a script.
It is fast for a plain reason. One pasted block can change several files and run the checks in one go, and the model only has to write it once, so there is no round trip per edit and no agent re-reading files and retrying. I have not timed it, so “fast” is how it feels, not a benchmark.
A wrong script can do real damage, so mine are built to fail early and quietly:
- Every block starts by moving into the project folder, so it cannot touch my other project.
- The script first checks that every line it plans to change really exists. If one marker is missing, it stops and writes nothing.
- I know what the output should look like before I run the block, because the assistant states it first. Anything different is my cue to stop.
- Each step is one commit on a branch made for the slice, so a wrong step is undone with a single revert.
- The type check and the build run before I move on.
None of that makes a script safe by itself. A marker that matches the wrong line still passes, so I read the diff before I commit. Even pasting has traps: zsh treats an exclamation mark inside a pasted block as history expansion, so my scripts avoid them.
I still own the result
None of this works if I let the AI decide everything. I still need to understand the requirements, choose the approach, review the code and test the result. When an agent hits a problem, I want to know why. When there is a technical choice, I look at the options before I take the first suggestion.
A large amount of generated code is not progress. Code that is correct, maintainable and solves the actual problem is.
I built this portfolio with this workflow. Its case study, Web Developer Personal Portfolio, lists my role as direction, design decisions, content, review and QA, with AI-assisted implementation.
These days a new slice starts the same way: a fresh chat, the handoff, and only the documents it names instead of all of them. I no longer explain my project from scratch, and my notes grow with every project. On a good day the only thing that stops me is the five-hour usage limit, and then I am itching for the window to reset so I can run the next step.
- Local AI
- Context Management
- Project Documentation
- Handoff Notes
- Scripted Edits
Planning a project and want it built in clear steps?
I like written scope, recorded decisions and work that anyone can pick up again. Tell me what you are building.