Skip to content

Commit a4d5674

Browse files
author
Darius Nguyen
committed
chore: update watcher starting
1 parent cfba683 commit a4d5674

5 files changed

Lines changed: 116 additions & 14 deletions

File tree

README.md

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,22 +87,48 @@ cd claude-code-nvim
8787

8888
## 🎯 Quick Start
8989

90+
### 🚀 **Method 1: Automatic (Recommended)**
91+
1. **Open Neovim** in your project directory
92+
2. **Press `<leader>Cs`** or run `:ClaudeCodeStart`
93+
3. **Done!** The plugin will guide you if the watcher isn't running
94+
95+
### 🛠️ **Method 2: Manual Control**
9096
1. **Start the file watcher:**
9197
```bash
98+
# In your project directory
9299
claude-code-watch
93100
```
94-
95-
2. **In Neovim, connect to the watcher:**
96-
```vim
101+
102+
2. **In Neovim, connect:**
103+
```bash
104+
# Press <leader>Cs or run:
97105
:ClaudeCodeStart
98106
```
99107

100-
3. **Use Claude Code as normal** - changes will appear instantly in Neovim!
108+
3. **Use Claude Code as normal** - changes appear instantly in Neovim!
101109

102-
4. **Review and accept/reject changes:**
103-
```vim
104-
:ClaudeCodeReview
105-
```
110+
### 📋 **Common Commands**
111+
- `<leader>Cr` - Review pending changes
112+
- `<leader>Ca` - Accept all changes
113+
- `<leader>Ct` - Check connection status
114+
- `<leader>ww` - Quick start (alternative binding)
115+
116+
### 🔧 **Auto-start Options**
117+
118+
**Option A: System Service (Set-and-forget)**
119+
```bash
120+
# Enable auto-start on login
121+
systemctl --user enable claude-code-watcher
122+
systemctl --user start claude-code-watcher
123+
```
124+
125+
**Option B: Plugin Auto-start**
126+
```lua
127+
require("claude-code-nvim").setup({
128+
auto_start_watcher = true, -- Plugin tries to start watcher
129+
auto_start = true, -- Auto-connect when Neovim opens
130+
})
131+
```
106132

107133
## 📋 Commands
108134

install.sh

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,52 @@ fi
159159
echo ""
160160
echo "Creating helper scripts..."
161161

162-
# Start script
162+
# Create start script in user's PATH
163+
mkdir -p "$HOME/.local/bin"
163164
cat > "$HOME/.local/bin/claude-code-watch" << EOF
164165
#!/bin/bash
165-
exec "$WATCHER_INSTALL_DIR/venv/bin/python" "$WATCHER_INSTALL_DIR/watcher.py"
166+
# Claude Code + Neovim Integration File Watcher
167+
# This script starts the file watcher service that monitors Claude Code changes
168+
169+
WATCHER_DIR="$WATCHER_INSTALL_DIR"
170+
PYTHON_BIN="\$WATCHER_DIR/venv/bin/python"
171+
WATCHER_SCRIPT="\$WATCHER_DIR/watcher.py"
172+
173+
if [ ! -f "\$PYTHON_BIN" ]; then
174+
echo "❌ Error: Python virtual environment not found at \$PYTHON_BIN"
175+
echo "Please run the installation script again: ./install.sh"
176+
exit 1
177+
fi
178+
179+
if [ ! -f "\$WATCHER_SCRIPT" ]; then
180+
echo "❌ Error: Watcher script not found at \$WATCHER_SCRIPT"
181+
echo "Please run the installation script again: ./install.sh"
182+
exit 1
183+
fi
184+
185+
echo "🚀 Starting Claude Code file watcher..."
186+
echo "📁 Watching: \$(pwd)"
187+
echo "🔌 Socket: /tmp/claude-code-nvim.sock"
188+
echo ""
189+
echo "💡 In Neovim, use :ClaudeCodeStart to connect"
190+
echo " Or press <leader>Cs to start the connection"
191+
echo ""
192+
echo "Press Ctrl+C to stop the watcher"
193+
echo ""
194+
195+
exec "\$PYTHON_BIN" "\$WATCHER_SCRIPT"
166196
EOF
167197
chmod +x "$HOME/.local/bin/claude-code-watch"
168198

199+
# Also create a desktop shortcut script
200+
cat > "$HOME/.local/bin/claude-code-watch-here" << EOF
201+
#!/bin/bash
202+
# Start Claude Code watcher in current directory
203+
cd "\$(pwd)"
204+
claude-code-watch
205+
EOF
206+
chmod +x "$HOME/.local/bin/claude-code-watch-here"
207+
169208
# Systemd service (Linux)
170209
if [ "$(uname)" = "Linux" ] && command -v systemctl &> /dev/null; then
171210
SERVICE_FILE="$HOME/.config/systemd/user/claude-code-watcher.service"

nvim-plugin/lua/claude-code-nvim/config.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local defaults = {
44
-- Connection settings
55
socket_path = '/tmp/claude-code-nvim.sock',
66
auto_start = true,
7+
auto_start_watcher = false, -- Try to start watcher automatically
78
auto_reconnect = true,
89
reconnect_delay = 5000, -- ms
910

nvim-plugin/lua/claude-code-nvim/init.lua

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,45 @@ function M.start()
4444
return
4545
end
4646

47+
-- Check if watcher might be startable
48+
local socket_exists = vim.fn.filereadable(M.state.config.socket_path) == 1
49+
if not socket_exists and M.state.config.auto_start_watcher then
50+
M._try_start_watcher()
51+
end
52+
4753
ipc.connect(function(success)
4854
if success then
4955
M.state.connected = true
5056
ui.update_statusline("connected")
51-
vim.notify("Connected to Claude Code watcher", vim.log.levels.INFO)
52-
else
53-
vim.notify("Failed to connect to Claude Code watcher", vim.log.levels.ERROR)
57+
vim.notify("✅ Connected to Claude Code watcher", vim.log.levels.INFO, { title = "Claude Code" })
5458
end
5559
end)
5660
end
5761

62+
-- Try to start the watcher automatically
63+
function M._try_start_watcher()
64+
vim.notify("🚀 Attempting to start Claude Code watcher...", vim.log.levels.INFO, { title = "Claude Code" })
65+
66+
-- Try to start using the installed command
67+
local handle = vim.fn.jobstart("claude-code-watch", {
68+
detach = true,
69+
on_exit = function(_, code)
70+
if code ~= 0 then
71+
vim.schedule(function()
72+
vim.notify("Failed to auto-start watcher. Please run 'claude-code-watch' manually.", vim.log.levels.WARN)
73+
end)
74+
end
75+
end
76+
})
77+
78+
if handle > 0 then
79+
-- Give it a moment to start
80+
vim.defer_fn(function()
81+
vim.notify("Watcher started! Connecting...", vim.log.levels.INFO)
82+
end, 1000)
83+
end
84+
end
85+
5886
function M.stop()
5987
if not M.state.connected then
6088
vim.notify("Not connected to Claude Code watcher", vim.log.levels.WARN)

nvim-plugin/lua/claude-code-nvim/ipc.lua

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,15 @@ function M.connect(callback)
1818
socket:connect(socket_path, function(err)
1919
if err then
2020
vim.schedule(function()
21-
vim.notify("Failed to connect: " .. err, vim.log.levels.ERROR)
21+
-- Show helpful error message
22+
local error_msg = "❌ Failed to connect to Claude Code watcher!\n\n" ..
23+
"🔧 To fix this:\n" ..
24+
" 1. Start the watcher: claude-code-watch\n" ..
25+
" 2. Or run: systemctl --user start claude-code-watcher\n" ..
26+
" 3. Then try :ClaudeCodeStart again\n\n" ..
27+
"💡 Tip: Run 'claude-code-watch' in your terminal first!"
28+
29+
vim.notify(error_msg, vim.log.levels.WARN, { title = "Claude Code" })
2230
if callback then callback(false) end
2331
end)
2432
return

0 commit comments

Comments
 (0)