Fixes claude --print which does not respect TEMP_FILE#138
Open
romank0 wants to merge 1 commit intoThePrimeagen:masterfrom
Open
Fixes claude --print which does not respect TEMP_FILE#138romank0 wants to merge 1 commit intoThePrimeagen:masterfrom
--print which does not respect TEMP_FILE#138romank0 wants to merge 1 commit intoThePrimeagen:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The ClaudeCodeProvider (and CursorAgentProvider) use claude
--printwhich is a non-interactive mode. The prompt instructs Claude to write replacement code to aTEMP_FILE, but--printmode may output the response to stdout instead of writing to the file. The plugin only reads results from the temp file via_retrieve_response, so when the response comes via stdout it gets silently discarded. This results in "response was empty, visual replacement aborted" for visual operations.Additionally,
--printmode with--dangerously-skip-permissionscan behave non-deterministically — sometimes Claude outputs code to stdout (wrapped in markdown fences), sometimes it uses tool use to write directly to the temp file. Both paths need to work.What
Added stdout capture support for providers that use
--printmode:_stdout_as_response()— new method onBaseProvider(returnsfalse), overridden totrueonClaudeCodeProviderandCursorAgentProvider. Signals that the provider may return results via stdout rather than writing to the temp file.strip_markdown_fences(text)— utility that stripslang ...wrappers that--printmode adds around code output.make_requestmodification — when_stdout_as_response()is true, accumulates stdout chunks during the request. On completion, if the accumulated stdout is non-empty (after trimming and fence-stripping), writes it to the temp file. If stdout is empty (meaning Claude wrote to the temp file directly via tool use), the existing temp file content is preserved.Testing
Unit tests added:
_stdout_as_response()returns correct values for all providersstrip_markdown_fenceshandles: fences with/without language identifiers, no fences, multi-line content, empty content, fences that don't wrap the whole text, whitespace-only inputManually tested via:
nvim --cmd "set rtp^=$(pwd)"and then using visual.Note
Medium Risk
Changes how provider output is captured/written to the temp file for
claude/cursor-agent--printmode, which can affect request completion behavior and response parsing. Covered by unit tests but touches core provider I/O paths.Overview
Fixes visual operations for providers using
--printby capturing stdout as the response when the CLI doesn’t write toTEMP_FILE.Adds
BaseProvider._stdout_as_response()andBaseProvider.strip_markdown_fences(), updatesmake_requestto optionally buffer stdout and write cleaned output back to the temp file on success, and enables this behavior forClaudeCodeProviderandCursorAgentProvider. Includes new unit tests for stdout-capture configuration and fence stripping, and updates.gitignoreto exclude.claude/settings.local.json.Written by Cursor Bugbot for commit 2aaf842. This will update automatically on new commits. Configure here.