Skip to content

Conversation

@RomneyDa
Copy link
Collaborator

@RomneyDa RomneyDa commented Jan 9, 2026

Description

  • Adds tools token counting
  • Truncates terminal, read file, fetch, diff, and search code output more intelligently, with configurable env vars

We already are very conservative about when to auto-compact, since we leave 35% or max tokens and then 80% of that, so compaction usually happens around 50% of actual context length. So it seems the only major cause of the context length exceeded issue is huge tool outputs.

Environment Variables

Environment Variable Tool Default
CONTINUE_CLI_BASH_MAX_OUTPUT_CHARS Bash 50,000
CONTINUE_CLI_BASH_MAX_OUTPUT_LINES Bash 1,000
CONTINUE_CLI_READ_FILE_MAX_OUTPUT_CHARS Read 100,000
CONTINUE_CLI_READ_FILE_MAX_OUTPUT_LINES Read 5,000
CONTINUE_CLI_FETCH_MAX_OUTPUT_LENGTH Fetch 20,000
CONTINUE_CLI_DIFF_MAX_OUTPUT_LENGTH Diff 50,000
CONTINUE_CLI_SEARCH_CODE_MAX_RESULTS Search 100
CONTINUE_CLI_SEARCH_CODE_MAX_RESULT_CHARS Search 1,000

partially a remake of #8122


Continue Tasks

Status Task Actions
▶️ Queued Create GitHub Issue (OS) View
▶️ Queued Update PostHog Dashboards View

Powered by Continue


Summary by cubic

Improves CLI output truncation and context length checks to prevent overflows. Keeps the most relevant output, counts system/tool tokens in auto-compaction, and adds configurable limits per tool.

  • New Features

    • Added truncateOutput utilities (from start/end, by lines/chars) with line-boundary snapping and env overrides; applied to Bash, Read, Fetch, Diff, and Search tools.
    • Introduced per-tool env vars and docs: CONTINUE_CLI_BASH_MAX_OUTPUT_CHARS/LINES, CONTINUE_CLI_READ_FILE_MAX_OUTPUT_CHARS/LINES, CONTINUE_CLI_FETCH_MAX_OUTPUT_LENGTH, CONTINUE_CLI_DIFF_MAX_OUTPUT_LENGTH, CONTINUE_CLI_SEARCH_CODE_MAX_RESULTS/RESULT_CHARS.
  • Refactors

    • shouldAutoCompact/validateContextLength now accept full context and use countTotalInputTokens/countToolDefinitionTokens; streaming/compaction paths pass tools/systemMessage through all checks.
    • Replaced ad-hoc truncation across tools (including bash timeout path) with the new utilities; expanded tests for truncation, token counting, and env parsing.

Written for commit d7b91f8. Summary will update on new commits.

@RomneyDa RomneyDa requested a review from a team as a code owner January 9, 2026 22:30
@RomneyDa RomneyDa requested review from Patrick-Erichsen and removed request for a team January 9, 2026 22:30
@continue
Copy link
Contributor

continue bot commented Jan 9, 2026

All Green - Keep your PRs mergeable

Learn more

All Green is an AI agent that automatically:

✅ Addresses code review comments

✅ Fixes failing CI checks

✅ Resolves merge conflicts


Unsubscribe from All Green comments

1 similar comment
@continue-staging
Copy link

All Green - Keep your PRs mergeable

Learn more

All Green is an AI agent that automatically:

✅ Addresses code review comments

✅ Fixes failing CI checks

✅ Resolves merge conflicts


Unsubscribe from All Green comments

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jan 9, 2026
@github-actions
Copy link

github-actions bot commented Jan 9, 2026

✅ Review Complete

Code Review Summary

⚠️ AI review failed. Please check the Continue API key and configuration.

Troubleshooting

  • Verify the CONTINUE_API_KEY secret is set correctly
  • Check that the organization and config path are valid
  • Ensure the Continue service is accessible

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Jan 9, 2026
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 11 files (changes from recent commits).

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="extensions/cli/src/util/tokenizer.ts">

<violation number="1" location="extensions/cli/src/util/tokenizer.ts:227">
P2: Empty enum array (`enum: []`) would subtract 3 tokens without adding any back, potentially resulting in negative token count. Consider adding a guard for empty arrays or ensuring `tokens` doesn't go negative.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

}

if (fieldEnum && Array.isArray(fieldEnum)) {
tokens -= 3;
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Empty enum array (enum: []) would subtract 3 tokens without adding any back, potentially resulting in negative token count. Consider adding a guard for empty arrays or ensuring tokens doesn't go negative.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At extensions/cli/src/util/tokenizer.ts, line 227:

<comment>Empty enum array (`enum: []`) would subtract 3 tokens without adding any back, potentially resulting in negative token count. Consider adding a guard for empty arrays or ensuring `tokens` doesn't go negative.</comment>

<file context>
@@ -196,16 +197,158 @@ export function calculateContextUsagePercentage(
+  }
+
+  if (fieldEnum && Array.isArray(fieldEnum)) {
+    tokens -= 3;
+    for (const e of fieldEnum) {
+      tokens += 3;
</file context>
Suggested change
tokens -= 3;
if (fieldEnum.length === 0) {
return tokens;
}
tokens -= 3;

✅ Addressed in d7b91f8

@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Jan 9, 2026
@github-project-automation github-project-automation bot moved this from Todo to In Progress in Issues and PRs Jan 10, 2026
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jan 10, 2026
@RomneyDa RomneyDa merged commit 5a94d6f into main Jan 10, 2026
57 of 60 checks passed
@RomneyDa RomneyDa deleted the dallin/context-length-exceeded branch January 10, 2026 01:38
@github-project-automation github-project-automation bot moved this from In Progress to Done in Issues and PRs Jan 10, 2026
@github-actions github-actions bot locked and limited conversation to collaborators Jan 10, 2026
@sestinj
Copy link
Contributor

sestinj commented Jan 13, 2026

🎉 This PR is included in version 1.38.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@sestinj
Copy link
Contributor

sestinj commented Jan 14, 2026

🎉 This PR is included in version 1.37.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

lgtm This PR has been approved by a maintainer released size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants