Skip to content

Fix vterm-copy-mode disrupted by anti-flicker timer in Claude Code sessions#241

Draft
Copilot wants to merge 5 commits intomainfrom
copilot/fix-vterm-copy-mode-issue
Draft

Fix vterm-copy-mode disrupted by anti-flicker timer in Claude Code sessions#241
Copilot wants to merge 5 commits intomainfrom
copilot/fix-vterm-copy-mode-issue

Conversation

Copy link
Contributor

Copilot AI commented Mar 18, 2026

Claude Code's complex ANSI output (spinners, progress redraws) consistently triggers the anti-flicker batching in vterm-smart-renderer. When the deferred render timer fired during vterm-copy-mode, it called vterm--filter and jumped the cursor back to the terminal bottom, making copy mode unusable. Simpler CLIs (Gemini, Codex) rarely hit the batching threshold, so they were unaffected.

Changes

  • ai-code-backends-infra--vterm-smart-renderer: adds (bound-and-true-p vterm-copy-mode) to the batching predicate so all incoming data is queued rather than immediately rendered while copy mode is active; the timer callback now clears its own reference unconditionally but skips calling vterm--filter when copy mode is still on, preserving the queue.

  • ai-code-backends-infra--vterm-flush-on-copy-mode-exit: new function that drains the pending render queue the moment the user exits copy mode — no output is lost.

  • ai-code-backends-infra--configure-vterm-buffer: installs the flush function as a buffer-local vterm-copy-mode-hook.

  • (defvar vterm-copy-mode): forward declaration added alongside the other vterm dynamic-variable declarations for clean byte-compilation.

;; Before: timer always called vterm--filter, disrupting copy position
(when ai-code-backends-infra--vterm-render-queue
  (let ((data ai-code-backends-infra--vterm-render-queue))
    (setq ai-code-backends-infra--vterm-render-queue nil
          ai-code-backends-infra--vterm-render-timer nil)
    (funcall orig-fun (get-buffer-process buf) data)))

;; After: skip render while in copy mode; flush via hook on exit
(setq ai-code-backends-infra--vterm-render-timer nil)
(when (and ai-code-backends-infra--vterm-render-queue
           (not (bound-and-true-p vterm-copy-mode)))
  (let ((data ai-code-backends-infra--vterm-render-queue))
    (setq ai-code-backends-infra--vterm-render-queue nil)
    (funcall orig-fun (get-buffer-process buf) data)))

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • www.reddit.com
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Cannot use Vterm-Copy mode for Claude (I can for other AI agent CLIs).</issue_title>
<issue_description>Described in https://www.reddit.com/r/emacs/comments/1rvytih/best_claude_code_emacs_integration/</issue_description>

<agent_instructions>check https://www.reddit.com/r/emacs/comments/1rvytih/best_claude_code_emacs_integration/</agent_instructions>

Comments on the Issue (you are @copilot in this section)


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Claude Code produces complex ANSI output that triggers the anti-flicker
batching in vterm-smart-renderer. When the deferred render timer fired
during vterm-copy-mode, it called vterm--filter and disrupted the user's
copy/scroll position. Other CLIs (Gemini, Codex) produced simpler output
that rarely triggered the batching, so they were unaffected.

Changes:
- Add (bound-and-true-p vterm-copy-mode) to the batching condition so all
  incoming data is queued (not immediately rendered) while copy mode is on
- In the render timer callback, clear the timer ref unconditionally but
  skip calling vterm--filter when vterm-copy-mode is still active,
  preserving the queue for later
- Add ai-code-backends-infra--vterm-flush-on-copy-mode-exit which flushes
  the pending render queue when the user exits copy mode (no output lost)
- Install the flush function buffer-locally on vterm-copy-mode-hook in
  ai-code-backends-infra--configure-vterm-buffer
- Declare vterm-copy-mode defvar for byte-compilation correctness
- Add 4 ERT tests covering the new copy-mode-aware behaviour

Co-authored-by: tninja <714625+tninja@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix Vterm-Copy mode issue for Claude Fix vterm-copy-mode disrupted by anti-flicker timer in Claude Code sessions Mar 18, 2026
Copilot AI requested a review from tninja March 18, 2026 04:23
davidwuchn and others added 3 commits March 18, 2026 21:24
## Summary

This PR adds a comprehensive behavior injection system for AI prompts,
enabling backend-agnostic behaviors integration with the ai-behaviors
repository.

## Features

### 1. Behavior Hashtags
- Operating modes: #=code, #=debug, #=research, #=review, #=spec, #=test
- Modifiers: #deep, #tdd, #challenge, #wide, #ground, #concise, etc.
- Constraint modifiers: #chinese, #english, #test-after, #strict-lint, etc.

### 2. Preset System
- Syntax: @preset-name to apply behavior presets
- 8 built-in presets: @tdd-dev, @thorough-debug, @quick-review, etc.
- Merging: @tdd-dev #chinese applies preset + adds constraint

### 3. Session-Scoped State
- Behaviors persist across prompts within a session
- Project-scoped: each git repository has independent behavior state
- Mode-line indicator shows active behaviors with color coding

### 4. Auto-Preset Detection
- Detects appropriate preset from context signals (filename, major-mode, git branch)

### 5. TAB Completion
- Type #dee TAB → completes to #deep
- Type @qui TAB → completes to @Quick-Fix or @quick-review

## Integration

Fully encapsulated via advice in ai-code-behaviors.el:
- Users must explicitly (require 'ai-code-behaviors)
- No changes to core ai-code files
- Integration via advice-add around ai-code--insert-prompt

## Also Includes

- ECA API fix: eca-chat-send-prompt signature change (session removed)

Co-authored-by: Wu David <davidwuchn@gmail.com>
…/ai-code-interface.el into copilot/fix-vterm-copy-mode-issue
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.

Cannot use Vterm-Copy mode for Claude (I can for other AI agent CLIs).

3 participants