What Is the `enabled_by_default` Property in TheFuck Rules?

The enabled_by_default property is a boolean flag defined in each rule module that determines whether TheFuck activates the rule automatically or requires explicit user configuration to enable it.

In the nvbn/thefuck repository, every correction rule can declare an enabled_by_default attribute that controls its baseline activation state. This property works in tandem with user settings to decide which rules participate when correcting failed shell commands.

How enabled_by_default Controls Rule Activation

The enabled_by_default property acts as the rule's "opt-out" flag. When TheFuck loads rule modules, it inspects this attribute to determine the initial state of each rule.

Rules Enabled by Default

When enabled_by_default is True or when the attribute is absent from the module, the rule is considered active automatically. Most rules in the repository follow this pattern, ensuring immediate utility after installation.

For example, in thefuck/rules/brew_unknown_command.py, the property is set dynamically based on system availability:


# thefuck/rules/brew_unknown_command.py

enabled_by_default = brew_available  # → True if Homebrew is present

Rules Disabled by Default

When enabled_by_default is explicitly set to False, the rule remains inactive unless the user explicitly includes it in their configuration. This pattern protects users from potentially dangerous or niche corrections.

The git_push_force rule demonstrates this safety pattern:


# thefuck/rules/git_push_force.py

enabled_by_default = False

The Logic Behind Rule Enablement in thefuck/types.py

The decision logic for rule activation resides in the Rule class within thefuck/types.py. This class encapsulates the enabled_by_default attribute and implements the is_enabled method that evaluates whether a rule should run.

Loading the Property from Rule Modules

When TheFuck imports a rule module, the Rule.from_path class method extracts the enabled_by_default attribute or defaults to True if undefined. This occurs in thefuck/types.py, lines 47-53:


# thefuck/types.py (lines 47-53)

return cls(name, rule_module.match,
           rule_module.get_new_command,
           getattr(rule_module, 'enabled_by_default', True),
           getattr(rule_module, 'side_effect', None),
           settings.priority.get(name, priority),
           getattr(rule_module, 'requires_output', True))

Evaluating Rule Status at Runtime

The is_enabled method (lines 62-66 in thefuck/types.py) determines whether a rule participates in the correction process by checking user settings against the enabled_by_default flag:


# thefuck/types.py (lines 62-66)

def is_enabled(self):
    """Returns `True` when rule enabled."""
    return (
        self.name in settings.rules
        or self.enabled_by_default
        and ALL_ENABLED in settings.rules
    )

This logic ensures that explicit user configuration in settings.rules always takes precedence over the default flag.

Configuration Overrides for enabled_by_default

Users can override the enabled_by_default property through several configuration mechanisms without modifying the rule source code.

Using settings.rules

Adding a rule name to the rules list in your configuration file forces the rule on, regardless of its enabled_by_default value. To enable the git_push_force rule (which defaults to disabled):


# ~/.config/thefuck/settings.py

rules = ['git_push_force', 'apt_get', 'git_commit_amend']

The ALL_ENABLED Token

When settings.rules contains the special ALL_ENABLED token (defined in thefuck/const.py), TheFuck activates all rules where enabled_by_default is True, while keeping rules with False disabled unless explicitly listed.


# ~/.config/thefuck/settings.py

rules = [ALL_ENABLED, 'git_push_force']  # All defaults + force push rule

Environment Variables

The THEFUCK_RULES environment variable provides a command-line override parsed in thefuck/conf.py (lines 85-90). This allows temporary activation of disabled rules:

export THEFUCK_RULES="git_push_force:DEFAULT_RULES"
thefuck <failed command>

Using exclude_rules

Conversely, the exclude_rules setting overrides enabled_by_default = True by explicitly disabling specific rules:


# ~/.config/thefuck/settings.py

exclude_rules = ['apt_get', 'brew_unknown_command']

Practical Examples of enabled_by_default in Rules

Dynamic Default Based on System State

The brew_unknown_command rule adjusts its default based on whether Homebrew is installed:


# thefuck/rules/brew_unknown_command.py

import os

brew_available = os.path.exists('/usr/local/bin/brew') or \
                 os.path.exists('/opt/homebrew/bin/brew')

enabled_by_default = brew_available

This ensures the rule only activates on systems where it can actually function.

Safety-Critical Disabled Default

The git_push_force rule requires explicit opt-in due to the destructive nature of force pushes:


# thefuck/rules/git_push_force.py

enabled_by_default = False

def match(command):
    return ('git' in command.script and 
            'push' in command.script and 
            'force' in command.script)

def get_new_command(command):
    return command.script.replace('push', 'push --force-with-lease')

Users must consciously enable this rule in their settings, preventing accidental data loss.

Summary

  • The enabled_by_default property in thefuck rules determines whether a rule is active automatically or requires explicit user configuration.
  • When set to True or undefined, rules activate immediately; when False, rules remain inactive unless added to settings.rules.
  • The Rule class in thefuck/types.py implements this logic through from_path (lines 47-53) and is_enabled (lines 62-66).
  • Users can override defaults via settings.rules, the ALL_ENABLED token, exclude_rules, or the THEFUCK_RULES environment variable.

Frequently Asked Questions

What happens if a rule doesn't define enabled_by_default?

If the enabled_by_default attribute is missing from a rule module, TheFuck defaults to treating it as True. According to the Rule.from_path implementation in thefuck/types.py (line 50), the code uses getattr(rule_module, 'enabled_by_default', True), ensuring backward compatibility and automatic activation for legacy rules.

Can I override enabled_by_default without editing rule files?

Yes. You can override the default activation state through your user configuration file at ~/.config/thefuck/settings.py by adding the rule name to the rules list (to force enable) or exclude_rules list (to force disable). Alternatively, set the THEFUCK_RULES environment variable before running the command, as parsed in thefuck/conf.py (lines 85-90).

How does enabled_by_default interact with rule priority?

The enabled_by_default flag determines whether a rule is considered at all, while the priority attribute (set via settings.priority or the rule's priority variable) determines the execution order among enabled rules. A rule with enabled_by_default = False will never run to check its priority unless explicitly enabled in settings, at which point its priority value competes with other active rules.

Where is the ALL_ENABLED constant defined?

The ALL_ENABLED sentinel token is defined in thefuck/const.py. When included in your settings.rules list, it signals TheFuck to automatically include all rules where enabled_by_default is True, while excluding those set to False unless explicitly listed alongside ALL_ENABLED.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →