chenhg5/cc-connect · error

session not found

Error message

session not found

What it means

DeleteSession (agent/claudecode/claudecode.go:630) deletes a Claude Code session transcript by removing ~/.claude/projects/<encoded-workdir>/<sessionID>.jsonl. Before deleting, it resolves the project directory that Claude Code created for the session's work_dir. When no directory under ~/.claude/projects matches the encoded work_dir, it throws 'session not found' — meaning Claude Code has never recorded any session for that working directory on this machine.

Source

Thrown at agent/claudecode/claudecode.go:630

	return sessions, nil
}

func (a *Agent) DeleteSession(_ context.Context, sessionID string) error {
	homeDir, err := os.UserHomeDir()
	if err != nil {
		return fmt.Errorf("claudecode: cannot determine home dir: %w", err)
	}
	a.mu.RLock()
	workDir := a.workDir
	a.mu.RUnlock()
	absWorkDir, err := filepath.Abs(workDir)
	if err != nil {
		return fmt.Errorf("claudecode: resolve work_dir: %w", err)
	}
	projectDir := findProjectDir(homeDir, absWorkDir)
	if projectDir == "" {
		return fmt.Errorf("session not found")
	}
	path := filepath.Join(projectDir, sessionID+".jsonl")
	if _, err := os.Stat(path); os.IsNotExist(err) {
		return fmt.Errorf("session file not found: %s", sessionID)
	}
	return os.Remove(path)
}

// extractStringContent attempts to extract a plain string from a json.RawMessage.
// Returns empty string if the raw message is not a JSON string.
func extractStringContent(raw json.RawMessage) string {
	if len(raw) == 0 {
		return ""
	}
	var s string
	if err := json.Unmarshal(raw, &s); err != nil {
		return ""
	}

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Verify the work_dir passed to DeleteSession matches the absolute working directory used when the session was created (use filepath.Abs of the same path; avoid '~' or relative paths).
  2. Run 'ls ~/.claude/projects' and confirm a directory whose name encodes the work_dir exists; if not, the session never existed for that directory.
  3. If CLAUDE_CONFIG_DIR points elsewhere, ensure the agent's homeDir resolution matches it, or clean up transcripts manually.
  4. Treat the error as idempotent: if the session is already gone, log and return success instead of surfacing an error to the user.

Example fix

// before
if err := agent.DeleteSession(ctx, "~/projects/app", sessionID); err != nil {
    return err
}
// after
abs, _ := filepath.Abs("~/projects/app") // resolve same way at session creation
abs, _ = expandTilde(abs)
if err := agent.DeleteSession(ctx, abs, sessionID); err != nil {
    if strings.Contains(err.Error(), "session not found") {
        return nil // already gone; idempotent delete
    }
    return err
}
Defensive patterns

Strategy: validation

Validate before calling

abs, err := filepath.Abs(workDir)
if err != nil { return err }
projects := filepath.Join(os.UserHomeDir(), ".claude", "projects")
if _, err := os.Stat(projects); err != nil {
    return fmt.Errorf("no claude projects dir for %s", abs)
}

Try / catch

if err := agent.DeleteSession(ctx, workDir, id); err != nil {
    if strings.Contains(err.Error(), "session not found") {
        return nil // idempotent
    }
    return err
}

Prevention

When it happens

Trigger: Calling DeleteSession(ctx, workDir, sessionID) where findProjectDir(homeDir, absWorkDir) returns "" — i.e. no directory under ~/.claude/projects matches any of the candidate encodings of absWorkDir (including the scan fallback).

Common situations: Deleting a session whose work_dir was configured differently (e.g. '~' instead of an absolute path resolved elsewhere, symlinked path, case difference on macOS); pointing CC-Connect at a machine or HOME that never ran Claude Code in that directory; sessions stored under a custom CLAUDE_CONFIG_DIR so ~/.claude/projects doesn't exist; deleting a session already removed by a concurrent caller.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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