Skip to content

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-js for 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:

Terminal window
# For text extraction and markdown conversion
sudo apt-get install pandoc
# For PDF and image conversion
sudo apt-get install libreoffice poppler-utils

Language-Specific Libraries:

Terminal window
# For document creation (JavaScript/TypeScript)
npm install -g docx
# For secure XML parsing (Python)
pip install defusedxml

Usage

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.

Terminal window
# Convert to markdown with all tracked changes visible
pandoc --track-changes=all input.docx -o output.md

For deep analysis (comments, media, or metadata), use the unpacking script:

Terminal window
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.md documentation for syntax and formatting rules.

This is the “gold standard” for professional document review. It involves a systematic process:

  1. Convert the document to Markdown to identify necessary changes.
  2. Unpack the OOXML structure.
  3. Implement changes in logical batches (3-10 changes) using the Python Document library.
  4. Verify using a minimal, precise edit principle to ensure only the changed text is marked, preserving the original RSID for 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:

Terminal window
# Step 1: Convert to PDF
soffice --headless --convert-to pdf document.docx
# Step 2: Convert PDF to JPEG images
pdftoppm -jpeg -r 150 document.pdf page

Workflow 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.