chenhg5/cc-connect · error

cannot read sessions directory %s: %w

Error message

cannot read sessions directory %s: %w

What it means

findAgentSessionID scans agent session directories (e.g. ~/.claude/projects/...) to map a project+key to an agent session ID. If os.ReadDir on a candidate directory fails with anything other than NotExist (which is skipped as a possibly-legacy dir), the walk aborts with this wrapped error, since silently ignoring permission/I-O errors could return a wrong or stale session.

Source

Thrown at cmd/cc-connect/session_id.go:101

		dataDir,
	}

	type candidate struct {
		agentID   string
		updatedAt int64 // unix nano from session UpdatedAt
	}
	var best *candidate
	var errCandidate *candidate // tracks the newest file where key was found but ID unavailable
	var definiteErr error

	for _, dir := range dirs {
		entries, err := os.ReadDir(dir)
		if err != nil {
			if os.IsNotExist(err) {
				continue // directory may not exist (e.g. legacy dir)
			}
			// Permission or other I/O errors should not be silently ignored.
			return "", fmt.Errorf("cannot read sessions directory %s: %w", dir, err)
		}
		for _, entry := range entries {
			if entry.IsDir() {
				continue
			}
			if !matchesProject(entry.Name(), project) {
				continue
			}

			agentID, updatedAt, found, err := readAgentSessionID(filepath.Join(dir, entry.Name()), sessionKey)
			if err != nil {
				// Key found but agent ID unavailable; record with its timestamp.
				if errCandidate == nil || updatedAt > errCandidate.updatedAt {
					errCandidate = &candidate{updatedAt: updatedAt}
					definiteErr = err
				}
				continue
			}

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Fix directory permissions: `chmod 755 <dir>` or chown to the user running cc-connect
  2. Check the mount/disk health if the error is EIO (dmesg, smartctl)
  3. Verify you are running as the same user that owns the agent's data directory (e.g. ~/.claude/projects)

Example fix

// before
drwx------ root root ~/.claude/projects   # cc-connect runs as 'cc'
// after
chown -R cc:cc ~/.claude/projects && chmod 755 ~/.claude/projects
Defensive patterns

Strategy: validation

Validate before calling

dir=~/.claude/projects; [ -r "$dir" ] || { echo "unreadable: $dir" >&2; exit 1; }

Prevention

When it happens

Trigger: Running `cc-connect agent-sid` (runAgentSID) while a sessions directory exists but is unreadable: wrong ownership, 0000 permissions, or an I/O error on the filesystem.

Common situations: Another user's home directory containing the agent data, restored backups with wrong ownership, EIO on failing disks or flaky network mounts.

Understand the failure class

Background: Permission denied / not authorized / 403 Forbidden: access-control rejections when the caller lacks the required role, grant, or ownership — this error's family across 18 libraries.

Related errors


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