{"record":{"id":"e081459e9d022951","repo":"jesseduffield/lazygit","slug":"error-parsing-custom-command-keybindings-context","errorCode":null,"errorMessage":"Error parsing custom command keybindings: context not provided (use context: 'global' for the global context). Key: %s, Command: %s","messagePattern":"Error parsing custom command keybindings: context not provided \\(use context: 'global' for the global context\\)\\. Key: (.+?), Command: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/gui/services/custom_commands/keybinding_creator.go","lineNumber":87,"sourceCode":"\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":69,"sourceCodeEnd":89,"githubUrl":"https://github.com/jesseduffield/lazygit/blob/c477a2959b229fbf3284be0d4d2904ab61ec3c94/pkg/gui/services/custom_commands/keybinding_creator.go#L69-L89","documentation":"Thrown by formatContextNotProvidedError when a custom command keybinding entry omits the 'context' field entirely. lazygit deliberately has no implicit default context (an unscoped key would silently shadow bindings everywhere), so it demands an explicit context, pointing you at 'global' for global bindings.","triggerScenarios":"A customCommands entry with 'key' and 'command' but no 'context' field. Keybinding generation encounters an empty Context string and raises this at startup.","commonSituations":"Porting old custom command configs from lazygit versions before contexts were mandatory; writing a quick global command and forgetting the context line.","solutions":["Add context: 'global' to the custom command entry for an always-active binding","Or scope it to the view where it should fire, e.g. context: 'files' or context: 'commits'"],"exampleFix":"# before\ncustomCommands:\n  - key: 'G'\n    command: 'git fetch --all'\n\n# after\ncustomCommands:\n  - key: 'G'\n    context: 'global'\n    command: 'git fetch --all'","handlingStrategy":"validation","validationCode":"# Fail if any custom command lacks a context\nyq '.customCommands[] | select(.context == null) | .key' ~/.config/lazygit/config.yml","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always write 'context:' on the same edit that adds a custom command keybinding","When porting configs from old lazygit versions, add contexts up front"],"tags":["lazygit","custom-commands","keybindings","config"],"backgroundTag":null,"analyzedSha":"c477a2959b229fbf3284be0d4d2904ab61ec3c94","analyzedAt":"2026-08-15T08:34:32.451Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}