jesseduffield/lazygit · error

Error parsing custom command keybindings: context not provid

Error message

Error parsing custom command keybindings: context not provided (use context: 'global' for the global context). Key: %s, Command: %s

What it means

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.

Source

Thrown at pkg/gui/services/custom_commands/keybinding_creator.go:87

	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. Add context: 'global' to the custom command entry for an always-active binding
  2. Or scope it to the view where it should fire, e.g. context: 'files' or context: 'commits'

Example fix

# before
customCommands:
  - key: 'G'
    command: 'git fetch --all'

# after
customCommands:
  - key: 'G'
    context: 'global'
    command: 'git fetch --all'
Defensive patterns

Strategy: validation

Validate before calling

# Fail if any custom command lacks a context
yq '.customCommands[] | select(.context == null) | .key' ~/.config/lazygit/config.yml

Prevention

When it happens

Trigger: A customCommands entry with 'key' and 'command' but no 'context' field. Keybinding generation encounters an empty Context string and raises this at startup.

Common situations: Porting old custom command configs from lazygit versions before contexts were mandatory; writing a quick global command and forgetting the context line.

Related errors


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