chenhg5/cc-connect · error

claudeSession: ensure shared prompt file: %w

Error message

claudeSession: ensure shared prompt file: %w

What it means

newClaudeSession (agent/claudecode/session.go:307) materializes the append system prompt before spawning the claude CLI. When neither a platform prompt nor an append prompt is configured, it reuses a shared prompt file created via ensureSharedSystemPromptFile; if that fails it cancels the context and returns 'claudeSession: ensure shared prompt file: %w'. This blocks session creation entirely — no claude process is started.

Source

Thrown at agent/claudecode/session.go:307

	//     per-spawn write, no cleanup needed.
	//   • 1% edge case (Slack/Weixin/MAX platform formatting or user-set
	//     append_system_prompt) — write a per-spawn temp file containing
	//     the merged content, removed on Close.
	//
	// Claude only reads the file at startup and never writes it, so the
	// shared file is safe under concurrent spawns.
	var promptFilePath string
	var promptFileIsShared bool
	// Issue #1655: when a.language is non-empty, this session gets the
	// localized cc-connect system prompt. When empty (legacy callers),
	// AgentSystemPromptForLang returns the English default — same bytes as
	// the pre-PR buildAppendSystemPrompt(core.AgentSystemPrompt(), ...) call.
	if appended := buildAppendSystemPrompt(core.AgentSystemPromptForLang(lang), platformPrompt, appendSystemPrompt); appended != "" {
		if platformPrompt == "" && appendSystemPrompt == "" {
			path, err := ensureSharedSystemPromptFile(ccDataDir, appended)
			if err != nil {
				cancel()
				return nil, fmt.Errorf("claudeSession: ensure shared prompt file: %w", err)
			}
			promptFilePath = path
			promptFileIsShared = true
		} else {
			path, err := writeTempAppendPromptFile(ccDataDir, appended)
			if err != nil {
				cancel()
				return nil, fmt.Errorf("claudeSession: write per-spawn prompt file: %w", err)
			}
			promptFilePath = path
		}
		innerArgs = append(innerArgs, "--append-system-prompt-file", promptFilePath)
	}

	if effort != "" {
		innerArgs = append(innerArgs, "--effort", effort)
	}
	if maxContextTokens > 0 {

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Check the wrapped cause: if it's mkdir/write permission denied, chown the ccDataDir to the user running cc-connect.
  2. Verify the cc data directory path in config exists and is writable: touch <ccDataDir>/.probe as the service user.
  3. Free disk space if the cause is ENOSPC.
  4. Configure a platformPrompt/appendSystemPrompt intentionally (which switches to the per-spawn temp file path) only if that is the desired design — the shared file is still required otherwise.

Example fix

// before (systemd unit)
[Service]
User=ccbot
# data dir owned by root → ensureSharedSystemPromptFile fails
// after
sudo chown -R ccbot:ccbot /var/lib/cc-connect
# or in config.toml point cc_data_dir somewhere the user owns
[agents.claudecode]
# data_dir = "/home/ccbot/.cc-connect"
Defensive patterns

Strategy: validation

Validate before calling

info, err := os.Stat(ccDataDir)
if err != nil || !info.IsDir() {
    return fmt.Errorf("cc data dir %s missing", ccDataDir)
}
if err := os.WriteFile(filepath.Join(ccDataDir, ".probe"), nil, 0o644); err != nil {
    return fmt.Errorf("cc data dir %s not writable by current user: %w", ccDataDir, err)
}

Try / catch

sess, err := agent.StartSession(ctx, opts)
if err != nil && strings.Contains(err.Error(), "ensure shared prompt file") {
    return nil, fmt.Errorf("cannot write to cc data dir; check ownership/permissions of the configured data directory: %w", err)
}

Prevention

When it happens

Trigger: Calling StartSession with no platformPrompt and no appendSystemPrompt, where ensureSharedSystemPromptFile fails: ccDataDir cannot be created (permission denied), the atomic write fails, chmod/chown fails, or the disk is full.

Common situations: ccDataDir under a read-only or root-owned path; running cc-connect as a service user without write access to the data dir; disk-full; SELinux/AppArmor blocking writes to the configured directory.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


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