DOCX Master
Introduction
The DOCX Master skill empowers Claude to interact with Microsoft Word documents as a professional editor. Rather than treating .docx files as opaque blobs, this skill provides a structured framework for deep analysis, precise editing, and programmatic creation of Office Open XML (OOXML) files.
Whether you are automating legal redlining, generating business reports from scratch, or extracting text for analysis, this skill provides the necessary tools to maintain formatting integrity and professional standards.
Key Capabilities:
- Precision Redlining: Implement tracked changes systematically in legal, academic, and business documents.
- Programmatic Creation: Generate new documents using
docx-jsfor consistent styling. - Structural Analysis: Unpack OOXML structures to access comments, metadata, and embedded media.
- Visual Conversion: Transform document pages into images for visual verification and analysis.
- Format Preservation: Edit existing documents while maintaining complex formatting and RSIDs.
Installation
To utilize the full suite of document manipulation tools, ensure the following dependencies are installed on your system:
System Packages:
# For text extraction and markdown conversionsudo apt-get install pandoc
# For PDF and image conversionsudo apt-get install libreoffice poppler-utilsLanguage-Specific Libraries:
# For document creation (JavaScript/TypeScript)npm install -g docx
# For secure XML parsing (Python)pip install defusedxmlUsage
The DOCX skill operates through specific workflows based on the complexity of the task.
1. Reading and Analysis
For simple text extraction, use Pandoc to convert the file to Markdown. This preserves the document structure and displays tracked changes clearly.
# Convert to markdown with all tracked changes visiblepandoc --track-changes=all input.docx -o output.mdFor deep analysis (comments, media, or metadata), use the unpacking script:
python ooxml/scripts/unpack.py <file.docx> <output_directory>2. Creating New Documents
When generating documents from scratch, the skill utilizes docx-js. This allows for a declarative approach to document building using Document, Paragraph, and TextRun components.
Note: Before creating documents, always refer to the full
docx-js.mddocumentation for syntax and formatting rules.
3. The Redlining Workflow (Recommended)
This is the “gold standard” for professional document review. It involves a systematic process:
- Convert the document to Markdown to identify necessary changes.
- Unpack the OOXML structure.
- Implement changes in logical batches (3-10 changes) using the Python Document library.
- Verify using a minimal, precise edit principle to ensure only the changed text is marked, preserving the original
RSIDfor unchanged runs.
Example of a precise edit in Python:
# GOOD: Only marks the specific change, preserving surrounding context'<w:r><w:t>The term is </w:t></w:r>' \'<w:del><w:r><w:delText>30</w:delText></w:r></w:del>' \'<w:ins><w:r><w:t>60</w:t></w:r></w:ins>' \'<w:r><w:t> days.</w:t></w:r>'4. Visual Verification
To see exactly how a document looks without opening a word processor:
# Step 1: Convert to PDFsoffice --headless --convert-to pdf document.docx
# Step 2: Convert PDF to JPEG imagespdftoppm -jpeg -r 150 document.pdf pageWorkflow Decision Tree
- Need to read text? Use Pandoc (Text Extraction).
- Need to see comments/media? Use Raw XML Access (Unpacking).
- Creating a new file? Use
docx-js(JavaScript). - Editing a legal/business doc? Use the Redlining Workflow (Python + OOXML).
- Simple edits to your own doc? Use Basic OOXML editing.
Code Style Guidelines
When writing scripts for document manipulation:
- Keep code concise and focused.
- Avoid verbose variable names or redundant print statements.
- Always perform a final verification by converting the edited document back to Markdown to ensure all changes were applied correctly.