{"record":{"id":"a58cbe9596382e8f","repo":"kovidgoyal/kitty","slug":"glfw-not-initialized-cannot-set-clipboard-data","errorCode":null,"errorMessage":"GLFW not initialized cannot set clipboard data","messagePattern":"GLFW not initialized cannot set clipboard data","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kitty/glfw.c","lineNumber":3435,"sourceCode":"    if (ret == NULL) return ans;\n    ans.data = PyBytes_AS_STRING(ret);\n    ans.sz = PyBytes_GET_SIZE(ret);\n    ans.free_data = ret;\n    return ans;\n}\n\nstatic PyObject *\nset_clipboard_data_types(PyObject *self UNUSED, PyObject *args) {\n    PyObject *mta;\n    int ctype;\n    if (!PyArg_ParseTuple(args, \"iO!\", &ctype, &PyTuple_Type, &mta)) return NULL;\n    if (glfwSetClipboardDataTypes) {\n        const char **mime_types = calloc(PyTuple_GET_SIZE(mta), sizeof(char *));\n        if (!mime_types) return PyErr_NoMemory();\n        for (Py_ssize_t i = 0; i < PyTuple_GET_SIZE(mta); i++) mime_types[i] = PyUnicode_AsUTF8(PyTuple_GET_ITEM(mta, i));\n        glfwSetClipboardDataTypes(ctype, mime_types, PyTuple_GET_SIZE(mta), get_clipboard_data);\n        free(mime_types);\n    } else log_error(\"GLFW not initialized cannot set clipboard data\");\n    if (PyErr_Occurred()) return NULL;\n    Py_RETURN_NONE;\n}\n\nstatic bool\nwrite_clipboard_data(void *callback, const char *data, size_t sz) {\n    Py_ssize_t z = sz;\n    if (data == NULL) {\n        PyErr_SetString(PyExc_RuntimeError, \"is_self_offer\");\n        return false;\n    }\n    PyObject *ret = PyObject_CallFunction(callback, \"y#\", data, z);\n    bool ok = false;\n    if (ret != NULL) {\n        ok = true;\n        Py_DECREF(ret);\n    }\n    return ok;","sourceCodeStart":3417,"sourceCodeEnd":3453,"githubUrl":"https://github.com/kovidgoyal/kitty/blob/6d5d0c440603ad9bdf6dcd599f73f6dde21acb44/kitty/glfw.c#L3417-L3453","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure at least one kitty OS window is open and GLFW is initialized before issuing clipboard commands (open a real kitty window first)","Run clipboard operations inside a running kitty session, not via kitty +kitten from another terminal","If building kitty from source, verify the bundled glfw was built fully (check that glfwSetClipboardDataTypes resolved) and rebuild"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# Only issue clipboard writes from inside a live kitty window:\nif [ -n \"$KITTY_WINDOW_ID\" ]; then kitty @ copy-to-clipboard <<< 'text'; fi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Gate clipboard remote-control on KITTY_WINDOW_ID / KITTY_LISTEN_ON being set","Don't run clipboard kittens from non-kitty terminals or SSH sessions expecting them to target kitty","Treat the result as a silent no-op: the function returns None rather than raising"],"tags":["kitty","clipboard","glfw","initialization","headless"],"backgroundTag":"clipboard-unavailable-not-initialized","analyzedSha":"6d5d0c440603ad9bdf6dcd599f73f6dde21acb44","analyzedAt":"2026-08-27T14:20:20.142Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}