{"record":{"id":"e2360e65f6a3acbd","repo":"charmbracelet/crush","slug":"session-id-q-is-ambiguous-d-matches-e2360e","errorCode":null,"errorMessage":"session ID %q is ambiguous (%d matches)","messagePattern":"session ID %q is ambiguous \\((.+?) matches\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmd/run.go","lineNumber":728,"sourceCode":"\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tvar matches []proto.Session\n\tfor _, s := range sessions {\n\t\thash := session.HashID(s.ID)\n\t\tif hash == id || strings.HasPrefix(hash, id) {\n\t\t\tmatches = append(matches, s)\n\t\t}\n\t}\n\n\tswitch len(matches) {\n\tcase 0:\n\t\treturn nil, fmt.Errorf(\"session %q not found\", id)\n\tcase 1:\n\t\treturn &matches[0], nil\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"session ID %q is ambiguous (%d matches)\", id, len(matches))\n\t}\n}\n","sourceCodeStart":710,"sourceCodeEnd":731,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/cmd/run.go#L710-L731","documentation":"When resolving a session by short hash prefix, if more than one session's hash starts with the given id, resolveSessionByID refuses to guess and reports the number of matches. This protects against resuming the wrong session from an ambiguous prefix.","triggerScenarios":"Passing a hash prefix shorter than needed such that multiple sessions share it as a prefix (e.g. `ab` matching ab12..., ab3f...), typically with 1-2 character prefixes or after many sessions accumulate.","commonSituations":"Hand-typing a very short prefix from memory; scripting with a fixed short prefix; sessions with similar timestamps producing hashes with common prefixes.","solutions":["Lengthen the hash prefix until it is unique (6-8 characters is usually enough).","Use the full session UUID for an exact match.","Run `crush session list` and copy the exact short hash shown for the target session."],"exampleFix":"// before\ncrush run --session ab \"prompt\"        # ambiguous: 3 matches\n// after\ncrush run --session ab12cd \"prompt\"    # unique prefix","handlingStrategy":"validation","validationCode":"sessions, _ := c.ListSessions(ctx, wsID)\nn := 0\nfor _, s := range sessions {\n    if strings.HasPrefix(session.HashID(s.ID), short) {\n        n++\n    }\n}\nif n > 1 {\n    return fmt.Errorf(\"prefix %q is ambiguous (%d matches); use a longer prefix\", short, n)\n}","typeGuard":"func uniquePrefix(sessions []proto.Session, prefix string) bool {\n    n := 0\n    for _, s := range sessions {\n        if strings.HasPrefix(session.HashID(s.ID), prefix) {\n            if n++; n > 1 {\n                return false\n            }\n        }\n    }\n    return n == 1\n}","tryCatchPattern":"sess, err := resolveSessionByID(ctx, c, wsID, short)\nif err != nil && strings.Contains(err.Error(), \"is ambiguous\") {\n    return fmt.Errorf(\"widen the prefix; try: crush session list | grep ^%s\", short)\n}","preventionTips":["Use at least 6-8 characters of the hash prefix.","Prefer the full UUID when uniqueness matters.","Never invent prefixes from memory; copy them from `crush session list`."],"tags":["cli","session","ambiguous-id"],"backgroundTag":"ambiguous-session-id","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}