HeadlinesBriefing favicon HeadlinesBriefing.com

AI Agents Edit Word Docs with docx-cli

Hacker News •
×

A new command-line interface tool, docx-cli, enables AI agents like Claude and Codex to read, edit, and comment on .docx files while preserving full formatting fidelity. Unlike typical AI approaches that involve unzipping OOXML and risk file corruption, docx-cli provides agents with commands and an annotated Markdown view, abstracting away the complex XML structure. This allows agents to interact with documents using stable locators, such as character offsets (e.g., `p3:5-20`), and ensures that custom styles, theme colors, and embedded objects remain intact.

The tool's efficacy was demonstrated in a benchmark comparing docx-cli against default AI agent skills. Across six real-world document tasks, including filling NDAs and redlining contracts, docx-cli achieved significantly higher task completion rates. On the cheaper Haiku model tier, docx-cli solved an average of 4.3 tasks out of 6, compared to 0.7 for the default skill, while using fewer tokens. With the stronger Sonnet model, docx-cli achieved a perfect 6/6 tasks, outperforming the default skill's 4/6. Critically, all documents processed by docx-cli opened correctly in Word, whereas the default method produced corrupted files in ~15% of cases.

Installation is straightforward via npm (requiring Bun) or as a standalone binary. The tool also integrates as an "Agent Skill," compatible with various AI agent harnesses. This skill ensures that agents can leverage docx-cli's capabilities, with the underlying CLI commands serving as the authoritative source for agent instructions via `--help` flags. The project focuses on making complex document manipulation accessible to even less capable AI models, addressing the practical challenges of AI-driven document processing.