PyCharm: Focus not returning to terminal after accepting diff in editor

Resolved 💬 3 comments Opened Feb 18, 2026 by genyk1p Closed Feb 18, 2026

Environment

  • Claude Code plugin version: 0.1.14-beta
  • Claude CLI version: 2.1.45
  • PyCharm: Professional 2025.3.2.1 (snap, build PY-253.30387)
  • Terminal engine: Reworked (JediTerm)
  • Operating System: Ubuntu, GNOME, Wayland
  • Shell: bash

Bug Description

After accepting a diff in PyCharm's editor (opened by Claude Code plugin via MCP openDiff tool), focus is not returned to the terminal. Instead, it lands on the previously active editor tab.

This is a regression or incomplete fix of #1257. The focusClaudeInTerminal method in DiffTools fileClosed handler does not reliably return focus to the terminal after the diff tab closes.

Steps to Reproduce

  1. Open any file in PyCharm editor (e.g. CLAUDE.md)
  2. Switch to the built-in terminal and run Claude Code
  3. Ask Claude Code to make an edit to a file (e.g. "edit test.py and add a function")
  4. Claude Code opens a split-view diff in the editor area
  5. Press Enter or click Apply to accept the diff
  6. The diff tab closes

Expected Behavior

Focus should return to the terminal where Claude Code is running, so the user can immediately continue typing.

Actual Behavior

Focus lands on CLAUDE.md (or whatever file was open before the diff tab). The user starts typing into the code editor instead of the terminal without realizing it. This is especially disruptive because:

  • There is no visual indication that focus has shifted
  • Keystrokes intended for Claude Code end up modifying source code files
  • User has to manually click back into the terminal every time a diff is accepted

Analysis

Decompiling the plugin JAR (claude-code-jetbrains-plugin-0.1.14-beta.jar) reveals:

  • DiffTools$addTools$1 contains references to both focusClaudeInTerminal and requestFocus
  • DiffTools$addTools$1$1$1$fileClosed$1 is the handler that fires when the diff editor is closed
  • TerminalUtil.focusClaudeInTerminal() exists and finds the correct terminal widget via process ID matching

The issue appears to be a race condition: when the diff tab closes, PyCharm's FileEditorManager activates the next editor tab before the plugin's fileClosed handler can call focusClaudeInTerminal. The terminal focus request likely gets overridden by the editor activation.

A possible fix would be to add a small delay (e.g. invokeLater or SwingUtilities.invokeLater) before calling focusClaudeInTerminal in the fileClosed handler, or to use ToolWindowManager.activate() which has stronger focus guarantees than requestFocus.

Workaround

Press Alt+F12 after accepting a diff to manually return focus to the terminal.

Related Issues

  • #1257 (closed) — original report, fix in 0.1.5-beta did not fully resolve the issue
  • #3332 (closed) — related ESC focus behavior

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗