Skip to content

Commit d27d0e4

Browse files
phiatclaude
andcommitted
Replace polling with fsnotify for real-time file watching
Use OS-native filesystem notifications (inotify/kqueue/FSEvents) via fsnotify instead of polling JSONL files every 500ms. Falls back to polling when fsnotify is unavailable (NFS, cross-FS WSL2). Debounces rapid writes with a 50ms coalesce window. Adds 11 new tests covering fsnotify integration, debounce behavior, and polling fallback. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5e4b297 commit d27d0e4

File tree

6 files changed

+732
-9
lines changed

6 files changed

+732
-9
lines changed

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ claude-esp
6363
| `-n` | Start from newest (skip history, live only) |
6464
| `-l` | List recent sessions |
6565
| `-a` | List active sessions (modified in last 5 min) |
66-
| `-p <ms>` | Poll interval in milliseconds (default 500) |
66+
| `-p <ms>` | Poll interval in ms (fallback mode only, default 500) |
6767
| `-v` | Show version |
6868
| `-h` | Show help |
6969

@@ -136,10 +136,12 @@ Background task outputs are stored in:
136136
The watcher:
137137

138138
1. Discovers active sessions (modified in last 5 minutes)
139-
2. Polls JSONL files every 500ms for new content
140-
3. Parses JSON lines and extracts thinking/tool_use/tool_result
141-
4. Discovers background tasks and correlates them with spawning agents
142-
5. Renders them in a TUI with tree navigation and filtering
139+
2. Uses OS-native filesystem notifications ([fsnotify](https://github.com/fsnotify/fsnotify)) to detect file changes in real-time (inotify on Linux, kqueue/FSEvents on macOS)
140+
3. Falls back to polling (configurable with `-p`) on filesystems that don't support notifications (NFS, some cross-FS WSL2 setups)
141+
4. Debounces rapid writes (50ms window) to efficiently handle burst output
142+
5. Parses JSON lines and extracts thinking/tool_use/tool_result
143+
6. Discovers background tasks and correlates them with spawning agents
144+
7. Renders them in a TUI with tree navigation and filtering
143145

144146
## tmux Setup
145147

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ require (
1515
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect
1616
github.com/charmbracelet/x/term v0.2.1 // indirect
1717
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
18+
github.com/fsnotify/fsnotify v1.9.0 // indirect
1819
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
1920
github.com/mattn/go-isatty v0.0.20 // indirect
2021
github.com/mattn/go-localereader v0.0.1 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQ
1616
github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=
1717
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
1818
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
19+
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
20+
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
1921
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
2022
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
2123
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=

0 commit comments

Comments
 (0)