chenhg5/cc-connect · error

opencodeSession: create image dir: %w

Error message

opencodeSession: create image dir: %w

What it means

Wraps a failed os.MkdirAll of <workDir>/.cc-connect/images in opencodeSession.stageImages. It fires when the workDir (or the staging subdir) is not writable, so image attachments cannot be staged for the outgoing prompt.

Source

Thrown at agent/opencode/session.go:125

	if err := cmd.Start(); err != nil {
		return fmt.Errorf("opencodeSession: start: %w", err)
	}

	s.wg.Add(1)
	go s.readLoop(cmd, stdout, &stderrBuf)

	return nil
}

func (s *opencodeSession) stageImages(prompt string, images []core.ImageAttachment) (string, []string, error) {
	if len(images) == 0 {
		return prompt, nil, nil
	}

	imgDir := filepath.Join(s.workDir, ".cc-connect", "images")
	if err := os.MkdirAll(imgDir, 0o755); err != nil {
		return "", nil, fmt.Errorf("opencodeSession: create image dir: %w", err)
	}

	imagePaths := make([]string, 0, len(images))
	for i, img := range images {
		ext := opencodeImageExt(img.MimeType)
		fname := fmt.Sprintf("img_%d_%d%s", time.Now().UnixMilli(), i, ext)
		fpath := filepath.Join(imgDir, fname)
		if err := os.WriteFile(fpath, img.Data, 0o644); err != nil {
			return "", nil, fmt.Errorf("opencodeSession: save image: %w", err)
		}
		imagePaths = append(imagePaths, fpath)
	}

	if prompt == "" {
		prompt = "Please analyze the attached image(s)."
	}

	return prompt, imagePaths, nil

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Fix write permissions on the project workDir
  2. Remove any file occupying the .cc-connect name
  3. Retry the image message after repair
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at agent/opencode/session.go:125 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/ba9fc276c55daba9. Report an issue: GitHub.