charmbracelet/crush · error

failed to start agent processing stream: %w

Error message

failed to start agent processing stream: %w

What it means

The non-interactive run starts the agent in a goroutine via app.AgentCoordinator.Run; if Run returns an error (stream could not even start — provider auth, request build failure, cancelled context), the goroutine pushes a wrapped response with this message. It means the agent never produced a successful processing stream.

Source

Thrown at internal/app/app.go:364

	// Automatically approve all permission requests for this non-interactive
	// session.
	app.Permissions.AutoApproveSession(sess.ID)

	// Report session identity to herdr.
	app.ReportCurrentSession(sess.ID)

	type response struct {
		result *fantasy.AgentResult
		err    error
	}
	done := make(chan response, 1)

	go func(ctx context.Context, sessionID, prompt string) {
		result, err := app.AgentCoordinator.Run(ctx, sess.ID, prompt)
		if err != nil {
			done <- response{
				err: fmt.Errorf("failed to start agent processing stream: %w", err),
			}
			return
		}
		done <- response{
			result: result,
		}
	}(ctx, sess.ID, prompt)

	messageEvents := app.Messages.Subscribe(ctx)
	messageReadBytes := make(map[string]int)
	var printed bool

	defer func() {
		if progress && stderrTTY {
			_, _ = fmt.Fprintf(os.Stderr, ansi.ResetProgressBar)
		}

		// Always print a newline at the end. If output is a TTY this will

View on GitHub (pinned to 7944b8e522)

Solutions

  1. Export the required provider API key in the environment
  2. Verify the selected/overridden model matches a configured provider
  3. Re-run with SLOG_LEVEL=debug to see the wrapped provider error
  4. Check network/proxy access from CI to the provider endpoint

Example fix

// before
crush run "task" // provider key not set in CI
// after
export ANTHROPIC_API_KEY="sk-ant-..."
crush run "task"
Defensive patterns

Strategy: validation

Validate before calling

if os.Getenv("ANTHROPIC_API_KEY") == "" && os.Getenv("OPENAI_API_KEY") == "" {
	return errors.New("no provider API key set")
}
if ctx.Err() != nil {
	return fmt.Errorf("context already done: %w", ctx.Err())
}

Try / catch

err := app.RunNonInteractive(ctx, w, prompt, "", "", true, "", false)
if err != nil && strings.Contains(err.Error(), "failed to start agent processing stream") {
	return fmt.Errorf("check provider credentials/model: %w", err)
}

Prevention

When it happens

Trigger: AgentCoordinator.Run fails immediately: missing/invalid API key for the selected provider, unknown model, request construction error, or ctx already cancelled when the goroutine runs.

Common situations: Missing ANTHROPIC_API_KEY/OPENAI_API_KEY in non-interactive (CI) environments; model override pointing at a provider with no credentials; rate/quota exhausted on first request; context deadline exceeded before the request started.

Related errors


AI-assisted analysis of charmbracelet/crush@7944b8e522 (2026-08-29). Data as JSON: /api/errors/33403c27fa65d4c8. Report an issue: GitHub.