{"record":{"id":"c8aa79268fcb96ca","repo":"jesseduffield/lazygit","slug":"error-when-setting-custom-command-keybindings-unk","errorCode":null,"errorMessage":"Error when setting custom command keybindings: unknown context: %s. Key: %s, Command: %s.\nPermitted contexts: %s","messagePattern":"Error when setting custom command keybindings: unknown context: (.+?)\\. Key: (.+?), Command: (.+?)\\.\nPermitted contexts: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/gui/services/custom_commands/keybinding_creator.go","lineNumber":83,"sourceCode":"\treturn viewNames, nil\n}\n\nfunc (self *KeybindingCreator) contextForContextKey(contextKey types.ContextKey) (types.Context, bool) {\n\tfor _, context := range self.c.Contexts().Flatten() {\n\t\tif context.GetKey() == contextKey {\n\t\t\treturn context, true\n\t\t}\n\t}\n\n\treturn nil, false\n}\n\nfunc formatUnknownContextError(customCommand config.CustomCommand) error {\n\tallContextKeyStrings := lo.Map(context.AllContextKeys, func(key types.ContextKey, _ int) string {\n\t\treturn string(key)\n\t})\n\n\treturn fmt.Errorf(\"Error when setting custom command keybindings: unknown context: %s. Key: %s, Command: %s.\\nPermitted contexts: %s\", customCommand.Context, customCommand.Key.String(), customCommand.Command, strings.Join(allContextKeyStrings, \", \"))\n}\n\nfunc formatContextNotProvidedError(customCommand config.CustomCommand) error {\n\treturn fmt.Errorf(\"Error parsing custom command keybindings: context not provided (use context: 'global' for the global context). Key: %s, Command: %s\", customCommand.Key.String(), customCommand.Command)\n}\n","sourceCodeStart":65,"sourceCodeEnd":89,"githubUrl":"https://github.com/jesseduffield/lazygit/blob/c477a2959b229fbf3284be0d4d2904ab61ec3c94/pkg/gui/services/custom_commands/keybinding_creator.go#L65-L89","documentation":"Thrown by formatUnknownContextError when a custom command's 'context' string does not correspond to any types.ContextKey in context.AllContextKeys. lazygit needs a valid context to know in which view the keybinding becomes active; an unrecognized name makes keybinding registration impossible.","triggerScenarios":"A customCommands entry with context: 'files-panel', 'commits', 'status-page', or any string not in AllContextKeys. The error message enumerates every permitted value, so compare against that list.","commonSituations":"Renaming a context in a lazygit upgrade (contexts are renamed between versions, e.g. 'subCommits' style changes); copying a custom command from an issue/thread written against a different version; using a view's display name instead of its context key.","solutions":["Read the 'Permitted contexts' list in the error itself and change the context to the closest valid key","Check docs-master/Config.md for your lazygit version's context keys and use the updated name","Use 'global' if the keybinding should work everywhere"],"exampleFix":"# before\ncustomCommands:\n  - key: 'e'\n    context: 'files-panel'\n    command: 'echo {{.SelectedFile}}'\n\n# after\ncustomCommands:\n  - key: 'e'\n    context: 'files'\n    command: 'echo {{.SelectedFile}}'","handlingStrategy":"validation","validationCode":"# Extract contexts from the running lazygit's error message list once, then diff against your config\nyq '.customCommands[].context' ~/.config/lazygit/config.yml | sort -u","typeGuard":null,"tryCatchPattern":null,"preventionTips":["After upgrading lazygit, re-check custom command contexts against the version's docs","Prefer context: 'global' unless the binding truly must be view-scoped"],"tags":["lazygit","custom-commands","keybindings","config","contexts"],"backgroundTag":null,"analyzedSha":"c477a2959b229fbf3284be0d4d2904ab61ec3c94","analyzedAt":"2026-08-15T08:34:32.451Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}