[BUG] `xlsx` skill's `recalc.py` fails on every Windows machine with `module 'socket' has no attribute 'AF_UNIX'`

Status Open
Reported on v2.1.209
Maintainer reply None cached
Activity 0 comments · opened Jul 18, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Environment:

  • OS: Windows 11 Home (build 10.0.26200)
  • Python: 3.14.6
  • Skill: anthropic-skills:xlsx, bundled scripts/recalc.py / scripts/office/soffice.py
  • LibreOffice: installed and working correctly when invoked directly

Description:

recalc.py (used to recalculate formulas after building/editing an .xlsx with openpyxl) fails immediately on Windows with:

{
  "error": "Could not prepare the LibreOffice environment: module 'socket' has no attribute 'AF_UNIX'"
}

This happens before LibreOffice is ever invoked, so it fails regardless of whether LibreOffice is installed or working.

Root cause:

scripts/office/soffice.py contains a _needs_shim() check meant to detect whether a sandboxed Linux/macOS environment is blocking AF_UNIX sockets (which LibreOffice's headless mode relies on internally):

def _needs_shim() -> bool:
    try:
        s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
        s.close()
        return False
    except OSError:
        return True

This assumes socket.AF_UNIX always exists as an attribute and only checks whether creating the socket is blocked at runtime (an OSError). On Windows, socket.AF_UNIX is not defined as an attribute at all in this Python build, so the line raises AttributeError instead of OSError. That's uncaught, so it propagates up through get_soffice_env() and recalc() as the generic "Could not prepare the LibreOffice environment" error.

Additionally, the fallback path this check leads to when a shim is needed (_ensure_shim()) compiles a C shared library with gcc -shared -fPIC ... -ldl and loads it via LD_PRELOAD — both Linux-specific mechanisms with no Windows equivalent (no LD_PRELOAD, no .so loading, and gcc is typically not present). So even patching the AttributeError wouldn't make the script functional on Windows; the whole sandbox-detection/shim approach is Linux/macOS-only by design.

Impact: recalc.py cannot run on any Windows machine, regardless of Python version or whether LibreOffice is installed and working.

Suggested fix:

  • Guard the AF_UNIX check with hasattr(socket, "AF_UNIX") (or catch AttributeError alongside OSError), and treat "attribute doesn't exist" as "no shim needed / not applicable" rather than crashing.
  • On Windows, skip the shim logic entirely and call soffice directly — e.g. soffice --headless --convert-to xlsx --outdir <dir> <file> works correctly to recalculate formulas and write cached values back, once LibreOffice is on PATH or its install path is known.

Workaround in the meantime: invoke soffice.exe --headless --convert-to xlsx --outdir <dir> <file.xlsx> directly instead of going through recalc.py.

What Should Happen?

recalc.py should successfully recalculate all formulas in the workbook using LibreOffice and report back a status of success or errors_found, the same as it does on Linux/macOS. On Windows, it should either skip the Unix-socket sandbox-detection/shim logic entirely (since that mechanism doesn't apply on Windows) and call soffice --headless --convert-to directly, or at minimum should not crash with an unhandled AttributeError before ever attempting to invoke LibreOffice.

Error Messages/Logs

Steps to Reproduce

On a Windows machine, install the xlsx skill (or have it available via Claude Code) and confirm LibreOffice is installed and working (e.g. soffice --headless --convert-to pdf test.xlsx succeeds on its own).
Create any valid .xlsx file — it doesn't need to contain formulas, since the crash happens before the file is even processed. For example, using openpyxl:
import openpyxl
wb = openpyxl.Workbook()
wb['Sheet'] = wb.active
wb.active['A1'] = 1
wb.active['A2'] = 2
wb.active['A3'] = '=A1+A2'
wb.save('test.xlsx')
Run the skill's recalculation script against that file:
python scripts/recalc.py test.xlsx 30
Observe the output.
Actual result:

{
"error": "Could not prepare the LibreOffice environment: module 'socket' has no attribute 'AF_UNIX'"
}
Expected result: a status of success (with total_formulas: 1, total_errors: 0), matching the behavior on Linux/macOS.

This reproduces on any Windows machine and any valid .xlsx file — the failure happens in office/soffice.py's _needs_shim() environment check, before the script ever reaches the file's actual formulas or invokes soffice.

Claude Model

Sonnet (default)

Is this a regression?

No, this never worked

Last Working Version

_No response_

Claude Code Version

2.1.209

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

Non-interactive/CI environment

Additional Information

_No response_

View original on GitHub ↗