Skip to content

Commit 35c3ac4

Browse files
authored
Merge pull request #33 from m7medVision/32-windows-error-filename-or-extension-is-too-long-when-using-anthropic-provider
Resolve Windows length issues with claude CLI
2 parents 980468d + 430534b commit 35c3ac4

1 file changed

Lines changed: 54 additions & 7 deletions

File tree

internal/provider/anthropic.go

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,37 @@ func (a *AnthropicProvider) GenerateCommitMessages(ctx context.Context, diff str
5656

5757
// Execute claude CLI with haiku model
5858
// Using -p flag for print mode and --model for model selection
59-
cmd := exec.CommandContext(ctx, "claude", "--model", a.model, "-p", fullPrompt)
59+
// Pipe prompt via stdin to avoid Windows command line length limits (8191 chars)
60+
cmd := exec.CommandContext(ctx, "claude", "--model", a.model, "-p", "-")
6061

61-
output, err := cmd.CombinedOutput()
62+
stdin, err := cmd.StdinPipe()
6263
if err != nil {
63-
return nil, fmt.Errorf("error executing claude CLI: %w\nOutput: %s", err, string(output))
64+
return nil, fmt.Errorf("error creating stdin pipe: %w", err)
6465
}
6566

67+
var outputBuf strings.Builder
68+
cmd.Stdout = &outputBuf
69+
cmd.Stderr = &outputBuf
70+
71+
if err := cmd.Start(); err != nil {
72+
return nil, fmt.Errorf("error starting claude CLI: %w", err)
73+
}
74+
75+
_, writeErr := stdin.Write([]byte(fullPrompt))
76+
stdin.Close()
77+
78+
waitErr := cmd.Wait()
79+
80+
if writeErr != nil {
81+
return nil, fmt.Errorf("error writing to claude CLI stdin: %w", writeErr)
82+
}
83+
84+
if waitErr != nil {
85+
return nil, fmt.Errorf("error executing claude CLI: %w\nOutput: %s", waitErr, outputBuf.String())
86+
}
87+
88+
output := []byte(outputBuf.String())
89+
6690
// Parse the output - split by newlines and clean
6791
content := string(output)
6892
lines := strings.Split(content, "\n")
@@ -139,14 +163,37 @@ func (a *AnthropicProvider) GeneratePRTitles(ctx context.Context, diff string) (
139163
fullPrompt := fmt.Sprintf("%s\n\nUser request: %s\n\nIMPORTANT: Generate exactly %d pull request titles, one per line. Do not include any other text, explanations, or formatting - just the PR titles.",
140164
systemMsg, userPrompt, a.numSuggestions)
141165

142-
// Execute claude CLI with the specified model
143-
cmd := exec.CommandContext(ctx, "claude", "--model", a.model, "-p", fullPrompt)
166+
// Pipe prompt via stdin to avoid Windows command line length limits (8191 chars)
167+
cmd := exec.CommandContext(ctx, "claude", "--model", a.model, "-p", "-")
144168

145-
output, err := cmd.CombinedOutput()
169+
stdin, err := cmd.StdinPipe()
146170
if err != nil {
147-
return nil, fmt.Errorf("error executing claude CLI: %w\nOutput: %s", err, string(output))
171+
return nil, fmt.Errorf("error creating stdin pipe: %w", err)
148172
}
149173

174+
var outputBuf strings.Builder
175+
cmd.Stdout = &outputBuf
176+
cmd.Stderr = &outputBuf
177+
178+
if err := cmd.Start(); err != nil {
179+
return nil, fmt.Errorf("error starting claude CLI: %w", err)
180+
}
181+
182+
_, writeErr := stdin.Write([]byte(fullPrompt))
183+
stdin.Close()
184+
185+
waitErr := cmd.Wait()
186+
187+
if writeErr != nil {
188+
return nil, fmt.Errorf("error writing to claude CLI stdin: %w", writeErr)
189+
}
190+
191+
if waitErr != nil {
192+
return nil, fmt.Errorf("error executing claude CLI: %w\nOutput: %s", waitErr, outputBuf.String())
193+
}
194+
195+
output := []byte(outputBuf.String())
196+
150197
// Parse the output - same logic as commit message generation
151198
content := string(output)
152199
lines := strings.Split(content, "\n")

0 commit comments

Comments
 (0)