Skip to content

feat: fire User autocmds for plugin state changes#227

Open
3dyuval wants to merge 1 commit intocoder:mainfrom
3dyuval:feat/user-events-222
Open

feat: fire User autocmds for plugin state changes#227
3dyuval wants to merge 1 commit intocoder:mainfrom
3dyuval:feat/user-events-222

Conversation

@3dyuval
Copy link
Copy Markdown

@3dyuval 3dyuval commented Mar 26, 2026

Summary

Fires doautocmd User <event> at key plugin state transitions so configs and other plugins can react without poking at internals.

Event When
ClaudeCodeDiffOpened A diff view is created (_open_native_diff)
ClaudeCodeDiffClosed A diff is accepted (_resolve_diff_as_saved) or rejected (_resolve_diff_as_rejected)
ClaudeCodeConnected A WebSocket client connects (on_connect)
ClaudeCodeDisconnected A WebSocket client disconnects (on_disconnect)
ClaudeCodeTerminalOpened Terminal window becomes visible (both snacks and native providers)
ClaudeCodeTerminalHidden Terminal window is hidden (both snacks and native providers)

Usage

Auto-hide the terminal float when a diff opens, so the diff buffers aren't covered:

vim.api.nvim_create_autocmd("User", {
  pattern = "ClaudeCodeDiffOpened",
  callback = function()
    local term = require("claudecode.terminal")
    if term.get_active_terminal_bufnr() then
      term.simple_toggle()
    end
  end,
})

Changes

  • lua/claudecode/diff.lua: ClaudeCodeDiffOpened before returning from _open_native_diff; ClaudeCodeDiffClosed in both _resolve_diff_as_saved and _resolve_diff_as_rejected
  • lua/claudecode/server/init.lua: ClaudeCodeConnected / ClaudeCodeDisconnected in the WebSocket callbacks, wrapped in vim.schedule since callbacks run off the main thread
  • lua/claudecode/terminal/snacks.lua: ClaudeCodeTerminalOpened / ClaudeCodeTerminalHidden in open, simple_toggle, and focus_toggle
  • lua/claudecode/terminal/native.lua: same events in open_terminal, hide_terminal, and show_hidden_terminal

Closes #222

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.

[FEATURE] Adding explicit User events for binding user functionality

1 participant