claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

IntelliJ Plugin: Diff tab automatically steals focus, causing accidental approvals

Open felipekj opened this issue 2 months ago • 6 comments

IntelliJ Plugin: Diff Tab Automatically Steals Focus

Problem Description

The Claude Code IntelliJ IDEA plugin opens diff approvals as new editor tabs and IntelliJ automatically switches to and focuses those tabs. This creates a dangerous UX issue: if the user is typing in the editor when the diff tab opens, their keystrokes are redirected to the diff editor, potentially causing accidental approval, rejection, or typing garbage into the diff without the user realizing they've lost context.

This issue occurs even with a single IntelliJ window, affecting any workflow where the user continues working while waiting for Claude Code responses.

Impact

Severity: High - Risk of approving code changes without review

  • User types in editor while waiting for Claude Code response
  • Diff tab suddenly opens and automatically receives focus
  • User's keypresses are now going to the diff tab instead of their code editor
  • User might accidentally approve/reject the diff without seeing it
  • User might inadvertently type into the diff, corrupting the review
  • Complete loss of context - user must remember what they were typing and where

This is particularly problematic during:

  • Active coding sessions with rapid back-and-forth interactions
  • Asynchronous workflows where the user continues working while waiting for responses
  • Any multi-tasking scenario where the user doesn't expect the tab switch

Steps to Reproduce

  1. Open IntelliJ IDEA with a project
  2. Start a Claude Code session and request a code change that requires diff approval
  3. Continue typing in your current editor while waiting for the response
  4. When the diff tab opens, observe that:
    • IntelliJ automatically switches to the new diff tab
    • The diff tab immediately receives keyboard focus
    • Your keypresses are now captured by the diff tab instead of your code editor
    • No visual/audio warning before focus transfer
    • Your typing context is completely lost

Expected Behavior

The diff tab should open without automatically switching focus:

  1. Diff opens in a background tab (visible but not focused)
  2. User maintains focus in their current editor
  3. Visual indicator (tab highlight, notification badge) shows diff awaits review
  4. User must explicitly click the tab or use a dedicated shortcut to review
  5. Alternatively: Show a non-intrusive notification that doesn't steal focus

Proposed Solutions

Option 1: Background Tab Opening (Recommended)

Open diff tabs in the background without switching focus:

FileEditorManager.getInstance(project).openFile(
    virtualFile,
    /* focusEditor = */ false,  // Don't switch to the tab
    /* searchForOpen = */ true
);
  • Diff tab opens but remains in background
  • Current editor retains focus
  • Tab highlight or notification indicator shows diff is ready
  • User explicitly switches to review when ready

Option 2: Non-Intrusive Notification First

Show a notification before opening the diff:

  • Display sticky notification: "Diff ready for review"
  • Notification includes "Review" button
  • Clicking button opens diff tab with focus
  • Diff doesn't open automatically until user clicks

Option 3: Split View Without Focus Change

Open diff in a split pane without changing editor focus:

  • Diff appears in split view or dedicated tool window
  • Current editor maintains keyboard focus
  • User can glance at diff without losing context
  • Requires explicit click to interact with diff

Option 4: Input Delay Protection

If focus stealing is unavoidable, add protection:

  • Ignore keyboard input for first 500-1000ms after diff opens
  • Display countdown/warning banner during delay period
  • Show "Diff loading... input disabled" message
  • Prevents accidental keypresses during transition

Option 5: Configuration Option

Add user preferences:

Settings → Tools → Claude Code → Diff Approval Behavior
[x] Open diffs in background tabs (don't auto-switch)
[ ] Show notification before opening diff
[ ] Delay keyboard input after diff opens (ms): [500]

Workarounds Attempted (All Failed)

The following configuration changes were attempted but did not prevent the focus stealing:

  1. IntelliJ Advanced Settings:

    • ide.disable.autofocus.dialogs = true
    • ide.disable.dialog.focus.stealing = true
    • No effect on editor tab focus behavior
  2. IntelliJ VM Options (idea64.vmoptions):

    • -Djava.awt.Window.locationByPlatform=false
    • -Dawt.nativeDoubleBuffering=true
    • -Dsun.java2d.xr.deferred=false
    • No effect on tab switching behavior
  3. Diff Settings (diff.xml):

    • Modified various diff component settings
    • No setting controls whether new tabs steal focus
  4. Window Manager Settings:

    • Attempted Mutter/Muffin focus prevention
    • Window manager doesn't control IntelliJ's internal tab behavior

Conclusion: IntelliJ's tab focus behavior is controlled by the plugin's file opening API calls, not by user-configurable settings. This requires a plugin code change.

Current Workaround (Manual)

Until fixed, the only reliable workaround is:

  1. Stop typing immediately when you send a Claude Code request
  2. Wait for the diff tab to appear before continuing work
  3. This defeats the purpose of asynchronous operation

Technical Details

Environment:

  • IntelliJ IDEA Community 2025.2
  • Linux (Mutter/Muffin window manager)
  • Claude Code plugin (latest version)

Root Cause: The plugin likely uses FileEditorManager.openFile() with focusEditor=true or requestFocus(), causing IntelliJ to automatically switch to and focus the new diff tab.

Affected Component: The code that opens the diff view for approval (likely in the plugin's diff/review handler)

Related Issues

This is similar to focus-stealing issues in other IDE plugins that open files for review:

  • GitHub Copilot's diff review behavior
  • Git conflict resolution tool window behavior
  • General IntelliJ tab switching on file open

Additional Context

The CLI version of Claude Code doesn't have this issue since:

  1. It operates in a terminal without automatic tab switching
  2. Diffs are displayed inline without context switching
  3. User explicitly chooses when to review

This is specific to the IntelliJ plugin implementation and how it opens diff editor tabs.


Suggested Priority: High Category: UX/Safety Affected Component: IntelliJ IDEA Plugin - Diff Tab Opening/Focus Management

felipekj avatar Oct 17 '25 19:10 felipekj

Found 1 possible duplicate issue:

  1. https://github.com/anthropics/claude-code/issues/1991

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

github-actions[bot] avatar Oct 17 '25 19:10 github-actions[bot]

Update: Workarounds Cause Side Effects

The VM options workarounds mentioned in this issue:

-Djava.awt.Window.locationByPlatform=false
-Dawt.nativeDoubleBuffering=true
-Dsun.java2d.xr.deferred=false

Not only did these workarounds fail to prevent the focus stealing, but they also caused significant rendering issues:

Side Effects Observed:

  • Severe UI blinking/flickering in IntelliJ IDEA
    • Project view file list blinks continuously
    • Claude Code terminal prompts and text blink
    • Overall IDE rendering instability
  • Issues particularly affect Intel integrated graphics (Intel Iris Xe on Linux/Mesa drivers)

Resolution:

Removing these VM options immediately resolved all blinking/flickering issues and restored normal IDE rendering.

Recommendation: Do not use these VM options as workarounds. They introduce worse problems than the original focus-stealing issue.

The focus-stealing problem still requires a proper fix in the plugin code (using focusEditor=false in file opening calls).

felipekj avatar Oct 20 '25 14:10 felipekj

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

github-actions[bot] avatar Dec 08 '25 10:12 github-actions[bot]

This is still happening. Commenting to keep issue open. Thank you 👍 :)

mohammedsahl avatar Dec 22 '25 21:12 mohammedsahl

still happening , Anthropic we pay you enough money for you to make the plugin stable as it is on vs code

Ruinous7 avatar Dec 23 '25 15:12 Ruinous7

Same issue here.

EkinStrop avatar Dec 23 '25 20:12 EkinStrop