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

  1. Read the 'Permitted contexts' list in the error itself and change the context to the closest valid key
  2. Check docs-master/Config.md for your lazygit version's context keys and use the updated name
  3. 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

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


AI-assisted analysis of jesseduffield/lazygit@c477a2959b (2026-08-15). Data as JSON: /api/errors/c8aa79268fcb96ca. Report an issue: GitHub.