Overview
The DOCX skill enables comprehensive Word document manipulation including creating professional documents from scratch, editing existing files with tracked changes and comments, and extracting content. A .docx file is a ZIP archive containing XML files that can be programmatically manipulated.Use this skill whenever working with Word documents (.docx files), including creating reports, memos, letters, templates, or any document requiring professional formatting like tables of contents, headings, page numbers, or letterheads.
Quick Reference
Reading and Converting Documents
Converting Legacy .doc Files
Legacy.doc files must be converted before editing:
Reading Content
Converting to Images
Accepting Tracked Changes
To produce a clean document with all tracked changes accepted:Creating New Documents
Setup and Installation
Install the docx-js library globally:Basic Document Structure
Page Size and Orientation
Page Size Configuration
Page Size Configuration
CRITICAL: docx-js defaults to A4, not US Letter. Always set page size explicitly:Common page sizes (DXA units):
Landscape orientation:
Styles and Headings
Use Arial as the default font (universally supported). Override built-in heading styles:Lists
Each reference creates INDEPENDENT numbering. Same reference continues (1,2,3 then 4,5,6), different reference restarts (1,2,3 then 1,2,3).
Tables
Table Configuration
Table Configuration
CRITICAL: Tables need dual widths - set both Width rules:
columnWidths on the table AND width on each cell.- Always use
WidthType.DXA— neverWidthType.PERCENTAGE(breaks in Google Docs) - Table width must equal sum of
columnWidths - Cell
widthmust match correspondingcolumnWidth - Cell
marginsare internal padding - reduce content area, not add to width - For full-width tables: use content width (page width minus margins)
Images
Hyperlinks and Bookmarks
Hyperlink Examples
Hyperlink Examples
External links:Internal links (bookmarks):
Headers, Footers, and Page Numbers
Table of Contents
Editing Existing Documents
Follow all 3 steps in order:Step 1: Unpack
Step 2: Edit XML
Edit files inunpacked/word/. Use “Claude” as the author for tracked changes and comments unless specified otherwise.
CRITICAL: Use smart quotes for new content:
Adding comments:
Step 3: Pack
Auto-Repair Features
Auto-Repair Features
Auto-repair will fix:
durableId>= 0x7FFFFFFF (regenerates valid ID)- Missing
xml:space="preserve"on<w:t>with whitespace
- Malformed XML
- Invalid element nesting
- Missing relationships
- Schema violations
XML Reference
Tracked Changes
Tracked Change Patterns
Tracked Change Patterns
Insertion:Deletion:Minimal edits - only mark what changes:Deleting entire paragraphs:
Comments
CRITICAL:<w:commentRangeStart> and <w:commentRangeEnd> are siblings of <w:r>, never inside <w:r>.
Critical Rules
Dependencies
- pandoc: Text extraction
- docx:
npm install -g docx(new documents) - LibreOffice: PDF conversion (auto-configured via
scripts/office/soffice.py) - Poppler:
pdftoppmfor images