jesseduffield/lazygit · error
Error when setting custom command keybindings: unknown conte
Error message
Error when setting custom command keybindings: unknown context: %s. Key: %s, Command: %s. Permitted contexts: %s
What it means
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.
Source
Thrown at pkg/gui/services/custom_commands/keybinding_creator.go:83
return viewNames, nil
}
func (self *KeybindingCreator) contextForContextKey(contextKey types.ContextKey) (types.Context, bool) {
for _, context := range self.c.Contexts().Flatten() {
if context.GetKey() == contextKey {
return context, true
}
}
return nil, false
}
func formatUnknownContextError(customCommand config.CustomCommand) error {
allContextKeyStrings := lo.Map(context.AllContextKeys, func(key types.ContextKey, _ int) string {
return string(key)
})
return 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, ", "))
}
func formatContextNotProvidedError(customCommand config.CustomCommand) error {
return 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)
}
View on GitHub (pinned to c477a2959b)
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
Example fix
# before
customCommands:
- key: 'e'
context: 'files-panel'
command: 'echo {{.SelectedFile}}'
# after
customCommands:
- key: 'e'
context: 'files'
command: 'echo {{.SelectedFile}}' Defensive patterns
Strategy: validation
Validate before calling
# Extract contexts from the running lazygit's error message list once, then diff against your config yq '.customCommands[].context' ~/.config/lazygit/config.yml | sort -u
Prevention
- After upgrading lazygit, re-check custom command contexts against the version's docs
- Prefer context: 'global' unless the binding truly must be view-scoped
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Error parsing custom command keybindings: context not provid
- Custom command prompt cannot have both a preset and a comman
- Unknown value for suggestionsPreset in custom command: %s. V
- No config file found
- {{disabledReason.Text}}
AI-assisted analysis of jesseduffield/lazygit@c477a2959b (2026-08-15).
Data as JSON: /api/errors/c8aa79268fcb96ca.
Report an issue: GitHub.