kovidgoyal/kitty · error

Failed to load cmd check function from {path} with error: {e

Error message

Failed to load cmd check function from {path} with error: {e}

What it means

kitty failed to import the user-supplied Python module (path from --remote-control-password-file style config, i.e. the config option pointing to a file defining is_cmd_allowed). It falls back to a default checker that will deny commands, so remote control effectively stops working.

Source

Thrown at kitty/remote_control.py:93

            )
            return {}
    return pcmd


class CMDChecker:
    def __call__(self, pcmd: dict[str, Any], window: Optional['Window'], from_socket: bool, extra_data: dict[str, Any]) -> bool | None:
        return False


@lru_cache(maxsize=64)
def is_cmd_allowed_loader(path: str) -> CMDChecker:
    import runpy

    try:
        m = runpy.run_path(path)
        func: CMDChecker = m['is_cmd_allowed']
    except Exception as e:
        log_error(f'Failed to load cmd check function from {path} with error: {e}')
        func = CMDChecker()
    return func


@lru_cache(maxsize=1024)
def fnmatch_pattern(pat: str) -> 're.Pattern[str]':
    from fnmatch import translate

    return re.compile(translate(pat))


def constant_time_lookup(passwords: dict[str, T], pw: str) -> T | None:
    result = None
    c = hmac.compare_digest
    for k, v in passwords.items():
        if c(k, pw):
            result = v
    return result

View on GitHub (pinned to 6d5d0c4406)

Solutions

  1. Test the file standalone: python3 /path/to/auth.py and fix any syntax/import errors
  2. Ensure the file defines a function named exactly is_cmd_allowed(pcmd, window, from_socket, extra_data) -> Optional[bool]
  3. Fix the path configured in kitty.conf so it points to the real file

Example fix

# auth.py must define:
def is_cmd_allowed(pcmd, window, from_socket, extra_data):
    return pcmd.get('cmd') == 'send-text'
Defensive patterns

Strategy: try-catch

Validate before calling

import runpy
m = runpy.run_path(path)
assert callable(m.get('is_cmd_allowed')), 'is_cmd_allowed missing or not callable'

Type guard

def loads_auth_module(path: str):
    m = runpy.run_path(path)
    f = m.get('is_cmd_allowed')
    return f if callable(f) else None

Try / catch

try:
    checker = loads_auth_module(path) or default_deny
except Exception:
    checker = default_deny  # fail closed

Prevention

When it happens

Trigger: runpy.run_path(path) or the m['is_cmd_allowed'] lookup raises — syntax error, missing is_cmd_allowed function, bad path — in is_cmd_allowed_loader.

Common situations: Typo in the path config, Python syntax errors in the auth script, script written for an older kitty API, or missing module-level imports in the script.

Related errors


AI-assisted analysis of kovidgoyal/kitty@6d5d0c4406 (2026-08-27). Data as JSON: /api/errors/7f55ac6daafacf79. Report an issue: GitHub.