{"record":{"id":"a3c6df5f46b86842","repo":"plandex-ai/plandex","slug":"invalid-context-index-s","errorCode":null,"errorMessage":"invalid context index: %s","messagePattern":"invalid context index: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/cmd/context_show.go","lineNumber":42,"sourceCode":"\t\tlib.MustResolveProject()\n\n\t\tnameOrIndex := args[0]\n\n\t\t// Get list of contexts first\n\t\tcontexts, err := api.Client.ListContext(lib.CurrentPlanId, lib.CurrentBranch)\n\t\tif err != nil {\n\t\t\tlog.Printf(\"Error listing contexts: %v\\n\", err)\n\t\t\treturn fmt.Errorf(\"error listing contexts: %v\", err)\n\t\t}\n\n\t\tvar contextId string\n\n\t\t// Try parsing as index first\n\t\tif idx, err := strconv.Atoi(nameOrIndex); err == nil {\n\t\t\t// Convert to 0-based index\n\t\t\tidx--\n\t\t\tif idx < 0 || idx >= len(contexts) {\n\t\t\t\treturn fmt.Errorf(\"invalid context index: %s\", nameOrIndex)\n\t\t\t}\n\t\t\tcontextId = contexts[idx].Id\n\t\t} else {\n\t\t\t// Try finding by name\n\t\t\tfound := false\n\t\t\tfor _, ctx := range contexts {\n\t\t\t\tif ctx.Name == nameOrIndex || ctx.FilePath == nameOrIndex {\n\t\t\t\t\tcontextId = ctx.Id\n\t\t\t\t\tfound = true\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t\tif !found {\n\t\t\t\treturn fmt.Errorf(\"no context found with name: %s\", nameOrIndex)\n\t\t\t}\n\t\t}\n\n\t\tres, apiErr := api.Client.GetContextBody(lib.CurrentPlanId, lib.CurrentBranch, contextId)","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/cmd/context_show.go#L24-L60","documentation":"When the argument to `plandex contexts show` parses as an integer, the CLI treats it as a 1-based list position, decrements it, and bounds-checks it against the fetched context list. If the resulting index is negative (i.e. you passed 0 or a negative number) or >= the number of contexts, it throws 'invalid context index: %s'. This is purely a client-side bounds error; no context was fetched.","triggerScenarios":"Running `plandex contexts show 0` or `plandex contexts show -1` (any value <= 0), or running `plandex contexts show N` where N is larger than the number of contexts in the current plan/branch (e.g. `show 5` when only 3 contexts exist).","commonSituations":"Stale numbering: the user copied an index from an earlier `plandex contexts` listing and contexts have since been removed; forgetting the list is 1-based and passing 0; running in a different plan/branch than where the index was noted.","solutions":["Run `plandex contexts` (or `plandex contexts ls`) to see the current 1-based list, then use an index between 1 and the list length.","If you intended a name, pass the context name or file path instead of a number (non-numeric args are matched by name).","Verify you are on the expected plan/branch; switch with `plandex checkout` if the list you referenced belongs to another branch.","Re-add the missing context with `plandex load` if it was removed."],"exampleFix":"// before\nplandex contexts show 0\n// after\nplandex contexts          # list contexts to get valid 1-based indexes\nplandex contexts show 1","handlingStrategy":"validation","validationCode":"# resolve a valid index before showing\nINDEX=$(plandex contexts | grep -n 'my-context' | cut -d: -f1)\nif [ -n \"$INDEX\" ] && [ \"$INDEX\" -ge 1 ]; then\n  plandex contexts show \"$INDEX\"\nfi","typeGuard":"func isValidContextIndex(arg string, count int) (int, bool) {\n    idx, err := strconv.Atoi(arg)\n    if err != nil {\n        return 0, false\n    }\n    idx-- // list is 1-based\n    if idx < 0 || idx >= count {\n        return 0, false\n    }\n    return idx, true\n}","tryCatchPattern":"if idx, ok := isValidContextIndex(arg, len(contexts)); ok {\n    ctx := contexts[idx]\n    _ = ctx\n} else {\n    return fmt.Errorf(\"index out of range 1..%d: %s\", len(contexts), arg)\n}","preventionTips":["Remember the list is 1-based; never pass 0 or negative numbers","Always re-list contexts (`plandex contexts`) before using an index in scripts — lists change as contexts are added/removed","Prefer referencing contexts by exact name or file path instead of index in automation","Confirm you are on the same plan/branch where the index was obtained"],"tags":["cli","validation","argument-parsing","go"],"backgroundTag":"argument-out-of-range","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}