Watch Claude Code edit files in real-time from your NeoVim editor.
- 🔌 Socket-based communication between Claude Code CLI and NeoVim
- 📂 Workspace-aware - Each directory gets its own socket
- 🎨 Visual highlights - See exactly what Claude changed with green backgrounds and gutter markers
- ⚡ Auto-focus - Files open automatically as Claude edits them
- 🔄 Re-enable friendly - Toggle on/off without errors
- 📜 Auto-scroll - Automatically scrolls to changed lines with configurable offset
- 🐛 Debug mode - Optional logging for troubleshooting
When Claude Code edits files, this plugin automatically:
- Opens the file in your main editor window
- Jumps to the edited line
- Highlights changed lines with green background
- Shows
●markers in the gutter - Displays notification with operation details
Perfect for pair programming with Claude or watching Claude work in another terminal/tab!
Using lazy.nvim
{
"zach-source/claude-follow-hook.nvim",
config = function()
require("claude-follow").setup({
setup_keymaps = true, -- Enable default keymaps
keymap_prefix = "<leader>af", -- Prefix for keymaps
})
end,
}Using packer.nvim
use {
"zach-source/claude-follow-hook.nvim",
config = function()
require("claude-follow").setup()
end
}require("claude-follow").setup({
-- Keymaps
setup_keymaps = true, -- Enable default keymaps (default: true)
keymap_prefix = "<leader>af", -- Keymap prefix (default: "<leader>af")
-- Socket settings
socket_prefix = "/tmp/nvim-follow-", -- Socket path prefix
socket_hash_length = 12, -- Length of CWD hash in socket name
-- UI customization
buffer_name = "[Claude Follow]", -- Name of the follow buffer
sign_text = "●", -- Sign text in gutter
sign_texthl = "DiagnosticInfo", -- Highlight group for sign text
sign_linehl = "DiffAdd", -- Highlight group for line background
highlight_duration = 5000, -- Duration to show highlights (ms)
-- Scroll behavior
scroll_to_change = true, -- Auto-scroll to changed lines (default: true)
scroll_offset = 5, -- Lines of context above/below (default: 5)
-- Debug
debug = false, -- Enable debug logging (default: false)
debug_log_path = "/tmp/claude-follow-mode-debug.log", -- Path for debug logs
})| Option | Type | Default | Description |
|---|---|---|---|
setup_keymaps |
boolean | true |
Enable default keymaps |
keymap_prefix |
string | "<leader>af" |
Prefix for all keymaps |
socket_prefix |
string | "/tmp/nvim-follow-" |
Socket file path prefix |
socket_hash_length |
number | 12 |
Length of CWD hash in socket name |
buffer_name |
string | "[Claude Follow]" |
Name of follow buffer |
sign_text |
string | "●" |
Character shown in gutter for changes |
sign_texthl |
string | "DiagnosticInfo" |
Highlight group for sign |
sign_linehl |
string | "DiffAdd" |
Highlight group for changed lines |
highlight_duration |
number | 5000 |
How long to show highlights (milliseconds) |
scroll_to_change |
boolean | true |
Auto-scroll viewport to changed lines |
scroll_offset |
number | 5 |
Lines of context above/below when scrolling |
debug |
boolean | false |
Enable debug logging in bash hook |
debug_log_path |
string | "/tmp/claude-follow-mode-debug.log" |
Debug log file path |
require("claude-follow").setup({
setup_keymaps = false, -- Disable keymaps, set up your own
})
-- Custom keymaps
vim.keymap.set("n", "<leader>wF", require("claude-follow").toggle):FollowModeOn- Enable follow mode:FollowModeOff- Disable follow mode:FollowModeToggle- Toggle follow mode:FollowModeStatus- Show status
<leader>af- Toggle follow mode<leader>afe- Enable follow mode<leader>afd- Disable follow mode<leader>afs- Status
Copy follow-mode-notify.sh to your Claude Code hooks directory:
cp follow-mode-notify.sh ~/.claude/hooks/
chmod +x ~/.claude/hooks/follow-mode-notify.shAdd to ~/.claude/settings.json:
{
"hooks": {
"PostToolUse": [
{
"matcher": "Write|Edit|MultiEdit",
"hooks": [
{
"type": "command",
"timeout": 2,
"command": "/Users/YOUR_USERNAME/.claude/hooks/follow-mode-notify.sh"
}
]
}
]
}
}Replace YOUR_USERNAME with your actual username, or use $HOME/.claude/hooks/follow-mode-notify.sh.
- NeoVim creates a Unix socket when follow mode is enabled:
/tmp/nvim-follow-<USER>-<CWD_HASH>.sock - The socket is unique per working directory (workspace-aware)
- Claude Code's PostToolUse hook sends file edits to this socket
- NeoVim receives the message and opens/highlights the file
Each directory gets its own socket based on SHA256 hash of the CWD:
~/repos/project1→nvim-follow-user-abc123.sock~/repos/project2→nvim-follow-user-def456.sock
This means:
- Multiple NeoVim instances can have follow mode enabled simultaneously
- Claude edits in project1 only affect NeoVim in project1
- No cross-contamination between workspaces
- NeoVim 0.9+ (for RPC support)
- Claude Code CLI installed
jqfor JSON parsing in the hook script- Unix-like system (macOS, Linux)
Run the test suite with:
make testOr manually with:
nvim --headless --noplugin -u tests/minimal_init.lua -c "PlenaryBustedDirectory tests/ { minimal_init = 'tests/minimal_init.lua' }"Note: Tests require plenary.nvim to be installed.
Perfect for multi-pane setups:
- One pane: NeoVim with follow mode enabled
- Another pane: Claude Code CLI editing files
- Watch Claude work in real-time!
Follow mode opens files automatically. Disable it when:
- Working with sensitive files
- Running untrusted Claude commands
- Want to avoid interruptions
Just run :FollowModeOff or toggle with your keymap.
Enable debug logging in your NeoVim config:
require("claude-follow").setup({
debug = true,
})Check the log:
tail -f /tmp/claude-follow-mode-debug.logDebug logs will only be written when debug = true is set in your config.
Ensure:
- Follow mode is enabled in NeoVim (
:FollowModeStatus) - Claude and NeoVim are in the same working directory
- Socket path matches: Run
:lua print(vim.g.follow_mode_socket)in NeoVim
Check:
- Signs are enabled:
:set signcolumn?(should beyesorauto) - Highlights work: Try
:sign place 1 line=1 name=ClaudeFollowChange buffer=1
MIT
Zach Taylor (@zach-source)
Issues and PRs welcome at: https://github.com/zach-source/claude-follow-hook.nvim