Skip to content

Commit 46ced5e

Browse files
committed
fix: Auto-accept claude trust prompt
1 parent c4d27b7 commit 46ced5e

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

session/tmux/tmux.go

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -140,27 +140,41 @@ func (t *TmuxSession) Start(workDir string) error {
140140
return fmt.Errorf("error restoring tmux session: %w", err)
141141
}
142142

143-
if t.program == ProgramClaude || strings.HasPrefix(t.program, ProgramAider) || strings.HasPrefix(t.program, ProgramGemini) {
143+
if strings.HasSuffix(t.program, ProgramClaude) || strings.HasSuffix(t.program, ProgramAider) || strings.HasSuffix(t.program, ProgramGemini) {
144144
searchString := "Do you trust the files in this folder?"
145145
tapFunc := t.TapEnter
146-
iterations := 5
147-
if t.program != ProgramClaude {
146+
maxWaitTime := 30 * time.Second // Much longer timeout for slower systems
147+
if !strings.HasSuffix(t.program, ProgramClaude) {
148148
searchString = "Open documentation url for more info"
149149
tapFunc = t.TapDAndEnter
150-
iterations = 10 // Aider takes longer to start :/
150+
maxWaitTime = 45 * time.Second // Aider/Gemini take longer to start
151151
}
152+
152153
// Deal with "do you trust the files" screen by sending an enter keystroke.
153-
for i := 0; i < iterations; i++ {
154-
time.Sleep(200 * time.Millisecond)
154+
// Use exponential backoff with longer timeout for reliability on slow systems
155+
startTime := time.Now()
156+
sleepDuration := 100 * time.Millisecond
157+
attempt := 0
158+
159+
for time.Since(startTime) < maxWaitTime {
160+
attempt++
161+
time.Sleep(sleepDuration)
155162
content, err := t.CapturePaneContent()
156163
if err != nil {
157-
log.ErrorLog.Printf("could not check 'do you trust the files screen': %v", err)
158-
}
159-
if strings.Contains(content, searchString) {
160-
if err := tapFunc(); err != nil {
161-
log.ErrorLog.Printf("could not tap enter on trust screen: %v", err)
164+
// Session might not be ready yet, continue waiting
165+
} else {
166+
if strings.Contains(content, searchString) {
167+
if err := tapFunc(); err != nil {
168+
log.ErrorLog.Printf("could not tap enter on trust screen: %v", err)
169+
}
170+
break
162171
}
163-
break
172+
}
173+
174+
// Exponential backoff with cap at 1 second
175+
sleepDuration = time.Duration(float64(sleepDuration) * 1.2)
176+
if sleepDuration > time.Second {
177+
sleepDuration = time.Second
164178
}
165179
}
166180
}

0 commit comments

Comments
 (0)