{"record":{"id":"570ccac62bb87ce8","repo":"chenhg5/cc-connect","slug":"cannot-read-sessions-directory-s-w","errorCode":null,"errorMessage":"cannot read sessions directory %s: %w","messagePattern":"cannot read sessions directory (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/cc-connect/session_id.go","lineNumber":101,"sourceCode":"\t\tdataDir,\n\t}\n\n\ttype candidate struct {\n\t\tagentID   string\n\t\tupdatedAt int64 // unix nano from session UpdatedAt\n\t}\n\tvar best *candidate\n\tvar errCandidate *candidate // tracks the newest file where key was found but ID unavailable\n\tvar definiteErr error\n\n\tfor _, dir := range dirs {\n\t\tentries, err := os.ReadDir(dir)\n\t\tif err != nil {\n\t\t\tif os.IsNotExist(err) {\n\t\t\t\tcontinue // directory may not exist (e.g. legacy dir)\n\t\t\t}\n\t\t\t// Permission or other I/O errors should not be silently ignored.\n\t\t\treturn \"\", fmt.Errorf(\"cannot read sessions directory %s: %w\", dir, err)\n\t\t}\n\t\tfor _, entry := range entries {\n\t\t\tif entry.IsDir() {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif !matchesProject(entry.Name(), project) {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tagentID, updatedAt, found, err := readAgentSessionID(filepath.Join(dir, entry.Name()), sessionKey)\n\t\t\tif err != nil {\n\t\t\t\t// Key found but agent ID unavailable; record with its timestamp.\n\t\t\t\tif errCandidate == nil || updatedAt > errCandidate.updatedAt {\n\t\t\t\t\terrCandidate = &candidate{updatedAt: updatedAt}\n\t\t\t\t\tdefiniteErr = err\n\t\t\t\t}\n\t\t\t\tcontinue\n\t\t\t}","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/cmd/cc-connect/session_id.go#L83-L119","documentation":"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.","triggerScenarios":"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.","commonSituations":"Another user's home directory containing the agent data, restored backups with wrong ownership, EIO on failing disks or flaky network mounts.","solutions":["Fix directory permissions: `chmod 755 <dir>` or chown to the user running cc-connect","Check the mount/disk health if the error is EIO (dmesg, smartctl)","Verify you are running as the same user that owns the agent's data directory (e.g. ~/.claude/projects)"],"exampleFix":"// before\ndrwx------ root root ~/.claude/projects   # cc-connect runs as 'cc'\n// after\nchown -R cc:cc ~/.claude/projects && chmod 755 ~/.claude/projects","handlingStrategy":"validation","validationCode":"dir=~/.claude/projects; [ -r \"$dir\" ] || { echo \"unreadable: $dir\" >&2; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run cc-connect as the same user that owns the agent data directory","Watch for ownership changes after backup restores","Monitor disks/mounts for I/O errors"],"tags":["cli","sessions","permissions","filesystem"],"backgroundTag":"permission-denied","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}