Skip to content

Fixes claude --print which does not respect TEMP_FILE#138

Open
romank0 wants to merge 1 commit intoThePrimeagen:masterfrom
romank0:claude-print-fix
Open

Fixes claude --print which does not respect TEMP_FILE#138
romank0 wants to merge 1 commit intoThePrimeagen:masterfrom
romank0:claude-print-fix

Conversation

@romank0
Copy link

@romank0 romank0 commented Feb 26, 2026

Why

The ClaudeCodeProvider (and CursorAgentProvider) use claude --print which is a non-interactive mode. The prompt instructs Claude to write replacement code to a TEMP_FILE, but --print mode 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, --print mode with --dangerously-skip-permissions can 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 --print mode:

  • _stdout_as_response() — new method on BaseProvider (returns false), overridden to true on ClaudeCodeProvider and CursorAgentProvider. Signals that the provider may return results via stdout rather than writing to the temp file.
  • strip_markdown_fences(text) — utility that strips lang ... wrappers that --print mode adds around code output.
  • make_request modification — 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 providers
  • strip_markdown_fences handles: fences with/without language identifiers, no fences, multi-line content, empty content, fences that don't wrap the whole text, whitespace-only input

Manually 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 --print mode, 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 --print by capturing stdout as the response when the CLI doesn’t write to TEMP_FILE.

Adds BaseProvider._stdout_as_response() and BaseProvider.strip_markdown_fences(), updates make_request to optionally buffer stdout and write cleaned output back to the temp file on success, and enables this behavior for ClaudeCodeProvider and CursorAgentProvider. Includes new unit tests for stdout-capture configuration and fence stripping, and updates .gitignore to exclude .claude/settings.local.json.

Written by Cursor Bugbot for commit 2aaf842. This will update automatically on new commits. Configure here.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant