Skip to content

Improve conversation lookup performance #10

@Fuabioo

Description

@Fuabioo

Problem

The findConversationFile function in internal/cli/show.go (lines 357-409) performs a linear scan across all project directories every time a conversation ID is looked up.

Evidence

func findConversationFile(id string) (string, error) {
    // Search in all projects
    projects, err := history.ListProjects(cfg.ProjectsDir)
    // ...
    for _, project := range projects {      // O(P) projects
        entries, err := os.ReadDir(project.Dir)  // O(F) files per project
        for _, entry := range entries {     // Linear string matching
            // ...
        }
    }
}

This function is called by ch show <id>, ch resume <id>, and ch agents <id>.

Impact

With many projects and conversations, every lookup scans potentially thousands of directory entries. For users with extensive Claude Code history, this could become noticeably slow.

Suggested Fix

Several options to consider:

  1. Start with current project first - Most lookups are for recent conversations in the current project
  2. Cache the session ID → file mapping - Build index once, reuse
  3. Use the existing SQLite DB - The sync feature already has SQLite; could add an index there
  4. Lazy/incremental approach - Cache discovered mappings as they're found

Files: internal/cli/show.go:357-409

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions