Launch offer: the first 1,000 users get Settl free for a year* Claim your spot
settlbuilding in public

Why it stops mid-file: the output cap, and how to shape requests around it

I build Settl, an expense-splitting app, solo with Claude, and I used to ask it for whole files. They came back cut off inside a function, no error, no closing brace. That is a hard cap on what one reply can contain, and typing "continue" is the worst available response to it.

Why generation stops with no error

There are two budgets, not one. The context window is what the model can read: on current frontier models, up to a million tokens. max_tokens is a separate cap on what it can write in one reply, and on those same models it tops out around 128,000. It reads a novel and writes a chapter.

max_tokens is a required request parameter, and client libraries often default it low. When generation reaches the number, the server stops emitting tokens wherever it happens to be. No exception is raised, because nothing failed: you asked for at most N tokens and you got N.

One more claim on that budget: with extended thinking on, reasoning tokens come out of the same allowance, so a hard problem spends part of it before the answer starts.

Nothing inside it is counting down

The model writes one token at a time, each conditioned on everything before it. No outline held aside, no running line count, no plan for the ending. It cannot notice it is at line 400 of 600, because it never decided the file was 600 lines.

That is why "keep it under 200 lines" is a nudge, not a constraint. It shapes the style without binding the length. The only hard number is the cap, and the model is never told what it is.

How to tell truncation from a bad answer

Through the API, stop_reason says it outright: end_turn means it finished, max_tokens means it was cut. Check it on anything you parse.

if resp.stop_reason == "max_tokens":
    raise Truncated("reply hit the output cap, do not parse this")

In a chat window there is no field, so read the shape: unbalanced braces, an unterminated string, a sentence ending mid-word, a numbered list that stops at 7 of 10. A syntactically incomplete last line means truncation. A complete last line with a wrong answer is a different problem.

Why continue makes it worse

The next turn conditions on the truncated text. The model reads its own half-file and has to infer indentation depth, which blocks are open, which imports it wrote, and what it intended next. It has no plan to consult, because it never had one.

So you get a re-opened block, duplicated imports, a helper defined twice, one value under two names. Ten minutes stitching two halves that were never written to fit.

Throw it away and ask smaller. When that is genuinely expensive, anchor hard:

Your last reply was cut off inside handleSubmit. Do not repeat anything.
Output only from this line onward, and stop when handleSubmit closes:

  const handleSubmit = async (e: FormEvent) => {

Code only, no commentary. Indent as if you are already two levels deep.

Four request shapes that fit the budget

The first one is only a wording change:

Change the rounding in src/lib/money.ts to round half-up at the cent.

Return a unified diff only. Do not rewrite the file, do not restate unchanged
functions, do not explain. If it touches more than one file, list the files
first, then give one diff per file.

When a long output is actually fine

Raise max_tokens and stream when the output genuinely is long: a new file with no version to diff against, generated fixtures, a bulk migration. Streaming exists so a large reply does not hit an HTTP timeout.

Do not raise it out of habit. A request needing 100,000 output tokens usually needed splitting, and it produces a reply nobody reviews line by line.

A file that cannot be rewritten in one reply is probably too big for one human review too. The output cap doubles as a detector for a module that wants splitting.

Run this on your codebase

I want to stop hitting output truncation. Do not write any code yet.

1. List the 10 largest source files with line counts, and for each estimate
   the output tokens a full rewrite would cost, at roughly 12 tokens a line.
2. Flag every file over 400 lines I am likely to ask you to rewrite whole.
   For the worst one, name the clearest seam to split along and which exports
   move to each side.
3. List every place our own code calls an LLM without checking stop_reason,
   with file and line.

Then give me two pieces of wording to keep: the phrasing that asks you for a
unified diff instead of a rewrite, and the phrasing that recovers a cut-off
reply, so I never type "continue" again.

Get the next one in your inbox