cline icon indicating copy to clipboard operation
cline copied to clipboard

Cline doesn't check size of terminal output

Open SolsticeSpectrum opened this issue 9 months ago • 2 comments

What happened?

If the LLM generates code which creates thousands or millions of lines, cline will read all that output, the CPU usage ramps up, VSCode eventually crashes and the task becomes unaccessible due to this error

[401987:0325/214251.030177:INFO:CONSOLE(35)] "%cTRACE color: #888 MainThreadFileSystemEventService#$watch(): request to start watching uncorrelated (extension: saoudrizwan.claude-dev, path: file:///home/user/challenge/rust_challenge, recursive: false, session: 0.21380126208054673, excludes: [], includes: ["**/.git/objects/**/**","**/.git/subtree-cache/**/**","**/.hg/store/**/**"])", source: vscode-file://vscode-app/usr/lib/code/out/vs/workbench/workbench.desktop.main.js (35)
[401987:0325/214252.031360:INFO:CONSOLE(746)] "%c[Extension Host] %crejected promise not handled within 1 second: SyntaxError: Unexpected end of JSON input %c(at console.<anonymous> (file:///usr/lib/code/out/vs/workbench/api/node/extensionHostProcess.js:159:26388)) color: blue color:  color: grey", source: vscode-file://vscode-app/usr/lib/code/out/vs/workbench/workbench.desktop.main.js (746)
[401987:0325/214252.031916:INFO:CONSOLE(746)] "%c[Extension Host] %cstack trace: SyntaxError: Unexpected end of JSON input
	at JSON.parse (<anonymous>)
	at uCe.getSavedClineMessages (/home/user/.vscode-oss/extensions/saoudrizwan.claude-dev-3.8.2-universal/dist/extension.js:2488:4550)
	at async uCe.resumeTaskFromHistory (/home/user/.vscode-oss/extensions/saoudrizwan.claude-dev-3.8.2-universal/dist/extension.js:2490:57) %c(at console.<anonymous> (file:///usr/lib/code/out/vs/workbench/api/node/extensionHostProcess.js:159:26388)) color: blue color:  color: grey", source: vscode-file://vscode-app/usr/lib/code/out/vs/workbench/workbench.desktop.main.js (746)
[401987:0325/214252.032584:INFO:CONSOLE(759)] "[saoudrizwan.claude-dev]Unexpected end of JSON input", source: vscode-file://vscode-app/usr/lib/code/out/vs/workbench/workbench.desktop.main.js (759)
[401987:0325/214252.032706:INFO:CONSOLE(759)] "SyntaxError: Unexpected end of JSON input
	at JSON.parse (<anonymous>)
	at uCe.getSavedClineMessages (/home/user/.vscode-oss/extensions/saoudrizwan.claude-dev-3.8.2-universal/dist/extension.js:2488:4550)
	at async uCe.resumeTaskFromHistory (/home/user/.vscode-oss/extensions/saoudrizwan.claude-dev-3.8.2-universal/dist/extension.js:2490:57)", source: vscode-file://vscode-app/usr/lib/code/out/vs/workbench/workbench.desktop.main.js (759)
[401987:0325/214255.093670:INFO:CONSOLE(35)] "%cDEBUG background: #eee; color: #888 Comments: URIs of continue on comments to add to storage .", source: vscode-file://vscode-app/usr/lib/code/out/vs/workbench/workbench.desktop.main.js (35)

There should probably be some check which will prevent Cline from reading too much text from console output to prevent it from dying when attempting this.

Steps to reproduce

  1. Force LLM to make code which generates a lot of output
  2. Cline attempts to send it all to LLM
  3. VSCode crashes

Relevant API REQUEST output


Operating System

Arch Linux

Cline Version

3.8.2

Additional context

No response

SolsticeSpectrum avatar Mar 25 '25 20:03 SolsticeSpectrum

This is something we're actively working on fixing.

dcbartlett avatar Mar 25 '25 21:03 dcbartlett

Here is the implementation that I use; feel free to take it or convert! The important part is the "if/else" near the end of the script.

Also note, the size limit I chose was 100 KB characters. It was based on Claude's 200 KB token limit; and, 1 word = ~1.3 tokens for Claude; and, I often use well over half of the 200 KB token limit while using Cline -- so, I would rather err on the side of caution as it were.

If you make a feature out of this I encourage you to add a UI setting so users can determine "how much they want to spend": i.e., close to the limit each time; or, e.g., "just show 1 KB of text of the results from beginning and end, and I'll spend more on tokens investigating the middle for those edge cases that need the full log." Depends on how prevalent those edge cases are, as to whether it'd be worth it for each person/team.

The addition of the checkpoints made this less necessary. Also Google's 2M token model; I perceive the token limits to be 'temporary' but that's speculation. Here's what I do, now:

I add the following paragraph to the Custom Instructions:

MUST use runcmd.sh for any terminal commands being run: put it at the beginning of all command lines, which MUST be a quoted string as the first and only parameter. This script keeps large outputs from blowing up the token limits and causing us to crash. Use head, tail, grep, etc to look inside it. runcmd.sh is available in the system PATH - do not prefix with './'.

And below is the script, runcmd.sh, which I put in the PATH -- this is on Linux; I don't have Windows or Mac development platforms at the moment. Hope this helps!

[Edit: that looked horrible, I will attach it instead.] [Edit2: had to rename it to end in .txt as .sh files aren't accepted by GitHub. Again, hope this helps!]

runcmd.sh.txt

libertyteeth avatar Mar 25 '25 22:03 libertyteeth

Hi all,

I think it would be really helpful if Cline had a built-in way to limit terminal command output—maybe with a configurable max bytes/lines setting. When output is truncated there could just be a small indicator (like an icon or question mark) next to the command result to show that the output was cut short, and users could hover for more info if needed.

Let me know if something like this is already in progress or if I should give it a go!

Thanks!

grahamseamans avatar Apr 12 '25 20:04 grahamseamans

Thanks for reporting! This has been consolidated into the master terminal issue #4356 which comprehensively addresses terminal output size management and capture problems.

celestial-vault avatar Jun 22 '25 21:06 celestial-vault