{"record":{"id":"a5e04cab77d4b819","repo":"continuedev/continue","slug":"token-limit-reached-file-range-likely-too-large-f","errorCode":null,"errorMessage":"Token limit reached. File/range likely too large for this edit","messagePattern":"Token limit reached\\. File/range likely too large for this edit","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"core/edit/recursiveStream.ts","lineNumber":55,"sourceCode":"  // let whiteSpaceAtEndOfBuffer = buffer.match(/\\s*$/)?.[0] ?? \"\"; // attempts at fixing whitespace bug with recursive boundaries\n\n  const injectApplyToken = type === \"apply\" && shouldInjectApplyToken(llm);\n  if (typeof prompt === \"string\") {\n    const finalPrompt = injectApplyToken ? prompt + APPLY_UNIQUE_TOKEN : prompt;\n\n    const generator = llm.streamComplete(finalPrompt, abortController.signal, {\n      raw: true,\n      prediction: undefined,\n      reasoning: false,\n    });\n\n    for await (const chunk of generator) {\n      yield chunk;\n      buffer += chunk;\n      totalTokens += countTokens(chunk);\n\n      if (totalTokens >= safeTokens) {\n        throw new Error(\n          \"Token limit reached. File/range likely too large for this edit\",\n        );\n        // const continuationPrompt = `${RECURSIVE_PROMPT}:\\n\\n${buffer}`;\n\n        // await generator.return(DUD_PROMPT_LOG); // kill the previous generator\n\n        // // TODO - Prediction capabilities lost because of partial input\n        // yield* recursiveStream(\n        //   llm,\n        //   abortController,\n        //   continuationPrompt,\n        //   undefined,\n        //   buffer,\n        //   true,\n        // ); // Recursively stream the continuation\n\n        // return;\n      }","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/continuedev/continue/blob/5522c6f44ca0ac3528b37244818fbfa39b5af470/core/edit/recursiveStream.ts#L37-L73","documentation":"recursiveStream (string variant) counts tokens of streamed chunks against a safe budget (contextLength minus reserve); exceeding it aborts with 'Token limit reached' because the recursive edit output would not fit.","triggerScenarios":"An edit/stream of a very large file or range where cumulative streamed tokens reach safeTokens before completion.","commonSituations":"Whole-file rewrites of huge files with a small-context model; maxTokens/completionOptions set too low; long recursive edit loops.","solutions":["Edit a smaller range/selection instead of the whole file","Use a model with larger contextLength","Lower completionOptions.maxTokens reserve or raise context budget","Split the edit into multiple smaller edits"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const est = countTokens(input);\nif (est > llm.contextLength - reserve) { splitIntoSmallerRanges(input); }","typeGuard":null,"tryCatchPattern":"catch (e) { if (e.message.startsWith('Token limit reached')) { split the file/range and retry with smaller inputs; } }","preventionTips":["Estimate token counts before whole-file edits","Prefer range/selection edits for large files"],"tags":["token-limits","edit","streaming","context-length"],"backgroundTag":"context-window-exceeded","analyzedSha":"5522c6f44ca0ac3528b37244818fbfa39b5af470","analyzedAt":"2026-08-27T11:28:54.683Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}