-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.go
More file actions
171 lines (148 loc) · 4.6 KB
/
main.go
File metadata and controls
171 lines (148 loc) · 4.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// Claude-esp streams Claude Code's hidden output (thinking, tool calls, subagents)
// to a separate terminal in real-time.
//
// Usage:
//
// claude-esp # Watch all active sessions
// claude-esp -n # Skip history, live only
// claude-esp -s <ID> # Watch a specific session
// claude-esp -a # List active sessions
// claude-esp -l # List recent sessions
//
// See https://github.com/phiat/claude-esp for full documentation.
package main
import (
"flag"
"fmt"
"os"
"time"
tea "github.com/charmbracelet/bubbletea"
"github.com/phiat/claude-esp/internal/tui"
"github.com/phiat/claude-esp/internal/watcher"
)
var (
version = "0.4.5"
)
func main() {
// Flags
sessionID := flag.String("s", "", "Watch a specific session by ID")
listSessions := flag.Bool("l", false, "List recent sessions")
listActive := flag.Bool("a", false, "List active sessions (modified in last 5 min)")
skipHistory := flag.Bool("n", false, "Start from newest (skip history, live only)")
pollMs := flag.Int("p", 500, "Poll interval in milliseconds (min 100)")
activeWindowStr := flag.String("w", "5m", "Active window duration (e.g. 30s, 2m, 5m)")
maxSessions := flag.Int("m", 0, "Max sessions to show in tree (0=unlimited)")
showVersion := flag.Bool("v", false, "Show version")
showHelp := flag.Bool("h", false, "Show help")
flag.Parse()
if *showHelp {
printHelp()
return
}
if *showVersion {
fmt.Printf("claude-esp v%s\n", version)
return
}
// Parse active window duration
activeWindow, err := time.ParseDuration(*activeWindowStr)
if err != nil {
fmt.Fprintf(os.Stderr, "Invalid active window duration %q: %v\n", *activeWindowStr, err)
os.Exit(1)
}
if *listActive {
sessions, err := watcher.ListActiveSessions(activeWindow)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
if len(sessions) == 0 {
fmt.Printf("No active sessions (none modified in last %s)\n", activeWindow)
return
}
fmt.Println("Active sessions:")
for _, s := range sessions {
status := " "
if s.IsActive {
status = "● "
}
fmt.Printf(" %s%s %s\n", status, s.ID[:min(12, len(s.ID))], truncatePath(s.ProjectPath, 40))
}
return
}
if *listSessions {
sessions, err := watcher.ListSessions(10)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
fmt.Println("Recent sessions:")
for _, s := range sessions {
status := " "
if s.IsActive {
status = "● "
}
fmt.Printf(" %s%s %s %s\n", status, s.Modified.Format("15:04:05"), s.ID[:min(12, len(s.ID))], truncatePath(s.ProjectPath, 30))
}
return
}
// Validate poll interval
pollInterval := time.Duration(*pollMs) * time.Millisecond
if pollInterval < 100*time.Millisecond {
pollInterval = 100 * time.Millisecond
}
// Run TUI
model := tui.NewModel(*sessionID, *skipHistory, pollInterval, activeWindow, *maxSessions)
p := tea.NewProgram(model, tea.WithAltScreen())
if _, err := p.Run(); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
}
func truncatePath(s string, max int) string {
if len(s) <= max {
return s
}
if max <= 3 {
return s[:max]
}
return "..." + s[len(s)-max+3:]
}
func printHelp() {
fmt.Printf(`claude-esp v%s
Stream Claude Code's hidden output (thinking, tool calls, subagents)
to a separate terminal.
USAGE:
claude-esp [OPTIONS]
OPTIONS:
-s <ID> Watch a specific session by ID
-l List recent sessions
-a List active sessions
-n Start from newest (skip history, live only)
-p <ms> Poll interval in ms, fallback mode only (default 500, min 100)
-w <dur> Active window duration (default 5m, e.g. 30s, 2m, 10m)
-m <N> Max sessions to show in tree (default 0=unlimited)
-v Show version
-h Show this help
ENVIRONMENT:
CLAUDE_HOME Override Claude config directory (default: ~/.claude)
KEYBINDINGS:
t Toggle thinking visibility
i Toggle tool input visibility
o Toggle tool output visibility
a Toggle auto-scroll
h Hide/show tree pane
A Toggle auto-discovery of new sessions
x/d Remove selected session (in tree)
tab Switch focus between tree and stream
j/k Navigate (tree) or scroll (stream)
space Toggle agent visibility (in tree)
g/G Go to top/bottom of stream
q Quit
USAGE:
# In one terminal, run Claude Code as normal
claude
# In another terminal, run the watcher
claude-esp
The watcher will automatically find the most recent active session.
`, version)
}