kovidgoyal/kitty · error

GLFW not initialized cannot set clipboard data

Error message

GLFW not initialized cannot set clipboard data

What it means

kitty attempted to set clipboard data but glfwSetClipboardDataTypes is NULL — the function pointer was never resolved, which happens when GLFW was not initialized or was built without the clipboard support kitty expects. The copy silently fails (Py_None returned) and the error is logged.

Source

Thrown at kitty/glfw.c:3435

    if (ret == NULL) return ans;
    ans.data = PyBytes_AS_STRING(ret);
    ans.sz = PyBytes_GET_SIZE(ret);
    ans.free_data = ret;
    return ans;
}

static PyObject *
set_clipboard_data_types(PyObject *self UNUSED, PyObject *args) {
    PyObject *mta;
    int ctype;
    if (!PyArg_ParseTuple(args, "iO!", &ctype, &PyTuple_Type, &mta)) return NULL;
    if (glfwSetClipboardDataTypes) {
        const char **mime_types = calloc(PyTuple_GET_SIZE(mta), sizeof(char *));
        if (!mime_types) return PyErr_NoMemory();
        for (Py_ssize_t i = 0; i < PyTuple_GET_SIZE(mta); i++) mime_types[i] = PyUnicode_AsUTF8(PyTuple_GET_ITEM(mta, i));
        glfwSetClipboardDataTypes(ctype, mime_types, PyTuple_GET_SIZE(mta), get_clipboard_data);
        free(mime_types);
    } else log_error("GLFW not initialized cannot set clipboard data");
    if (PyErr_Occurred()) return NULL;
    Py_RETURN_NONE;
}

static bool
write_clipboard_data(void *callback, const char *data, size_t sz) {
    Py_ssize_t z = sz;
    if (data == NULL) {
        PyErr_SetString(PyExc_RuntimeError, "is_self_offer");
        return false;
    }
    PyObject *ret = PyObject_CallFunction(callback, "y#", data, z);
    bool ok = false;
    if (ret != NULL) {
        ok = true;
        Py_DECREF(ret);
    }
    return ok;

View on GitHub (pinned to 6d5d0c4406)

Solutions

  1. Ensure at least one kitty OS window is open and GLFW is initialized before issuing clipboard commands (open a real kitty window first)
  2. Run clipboard operations inside a running kitty session, not via kitty +kitten from another terminal
  3. If building kitty from source, verify the bundled glfw was built fully (check that glfwSetClipboardDataTypes resolved) and rebuild
Defensive patterns

Strategy: validation

Validate before calling

# Only issue clipboard writes from inside a live kitty window:
if [ -n "$KITTY_WINDOW_ID" ]; then kitty @ copy-to-clipboard <<< 'text'; fi

Prevention

When it happens

Trigger: Calling kitty's set_clipboard_data / remote-control copy (kitty @ copy-to-clipboard, or kittens that write to the clipboard) before any OS window exists, after GLFW termination, or in a custom build lacking the clipboard patch.

Common situations: Running clipboard operations headless (kitty +kitten over SSH with no windows); calling copy during shutdown; mismatched glfw/kitty versions where the clipboard extension symbols are absent.

Related errors


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