MCPInstall

docx

Creates, reads, edits, and manipulates Word documents (.docx files) or Word templates (.dotx files). Triggers include: any mention of 'Word doc', 'word document', '.docx', '.dotx', or requests to produce professional documents with formatting like tables of contents, headings, page numbers, or letterheads. Also use when extracting or reorganizing content from .docx or .dotx files, inserting or replacing images in documents, performing find-and-replace in Word files, working with tracked changes or comments, or converting content into a polished Word document. If the user asks for a 'report', 'memo', 'letter', 'template', or similar deliverable as a Word or .docx file, use this skill. Do NOT use for PDFs, spreadsheets, Google Docs, or general coding tasks unrelated to document generation.

Installs
1.8K
Last 24h
—
Trending rank
—
Security
Not audited

Install

Works with every agent the skills CLI supports.

npx skills add https://github.com/k-dense-ai/scientific-agent-skills --skill docx
  1. 01

    Install

    Run the command in your project. The CLI asks which agents to install for.

  2. 02

    Describe the task

    Ask your agent for something this skill covers. It loads docx automatically when relevant.

  3. 03

    Review the result

    The agent follows the SKILL.md steps, scripts and references bundled with the skill.

SKILL.md

The instructions your agent reads when the skill is triggered.

DOCX creation, editing, and analysis

A .docx is a ZIP archive of XML files. Choose your approach by task:

TaskApproach
Create a new documentWrite a docx (npm) script — see gotchas below
Fill placeholders in a templatepatchDocument({ data, outputType, patches }) from docx
Edit arbitrary existing contentSafely unpack → edit the relevant OOXML parts → repackage
Read contentpandoc -f docx -t markdown --track-changes=all file.docx for review; accept for the accepted text view

Script paths below are relative to this skill's directory.

Creating with docx-js — gotchas

Examples target docx 9.8.1. Check node -p "require.resolve('docx')" in the script's project first. If absent, install it there with npm install docx@9.8.1; preinstallation is environment-specific. These are the main layout constraints:

  • Page size defaults to A4. For US Letter set page: { size: { width: 12240, height: 15840 } } (DXA; 1440 = 1″).
  • Landscape: pass portrait dimensions and orientation: PageOrientation.LANDSCAPE — docx-js swaps width/height internally.
  • Tables: for predictable fixed geometry, use layout: TableLayoutType.FIXED, table width: { size, type: WidthType.DXA }, numeric columnWidths in DXA, and matching widths on cells. With spans, sum the spanned columns. Percentage widths are supported, but cross-editor layout needs visual verification.
  • Table shading: use ShadingType.CLEAR with fill for a plain background; SOLID uses the foreground pattern color, not just fill.
  • Lists: never insert • literally; use a numbering config with LevelFormat.BULLET.
  • ImageRun requires type: ("png", "jpg", …).
  • PageBreak must be inside a Paragraph.
  • Paragraphs and line breaks: use separate Paragraph elements for paragraphs; new TextRun({ break: 1, text: "Next line" }) gives a line break within a paragraph. Do not expect \n in a plain text string to create paragraphs.
  • TOC: built-in HeadingLevel.* works with headingStyleRange. For custom styles use stylesWithLevels, or outlineLevel with useAppliedParagraphOutlineLevel: true. Update the TOC field in Word/LibreOffice before checking page numbers; creating a field does not calculate pagination.
  • Don't use a table as a horizontal rule — use a paragraph bottom border instead.
  • Dot-leader / right-aligned-on-same-line: use PositionalTab (alignment: PositionalTabAlignment.RIGHT, relativeTo: PositionalTabRelativeTo.MARGIN, leader: PositionalTabLeader.DOT) inside a TextRun, not literal . or space padding. LibreOffice 26.2.4.2 did not render that positional leader/alignment in the smoke test; use paragraph tabStops plus a Tab run when that renderer must reproduce it.

Small creation and template example

Run this CommonJS script with node example.cjs. patchDocument replaces {{name}} without requiring a complete document rebuild; it is a placeholder patcher, not a general Word document editing object model.

const fs = require("node:fs/promises");
const { Document, Packer, Paragraph, TextRun, HeadingLevel,
        patchDocument, PatchType } = require("docx");

async function main() {
  const document = new Document({ sections: [{
    properties: { page: { size: { width: 12240, height: 15840 } } },
    children: [
      new Paragraph({ text: "Research memo", heading: HeadingLevel.HEADING_1 }),
      new Paragraph("Prepared for {{name}}"),
    ],
  }] });
  const template = await Packer.toBuffer(document);
  const output = await patchDocument({
    data: template, outputType: "nodebuffer",
    patches: { name: { type: PatchType.PARAGRAPH,
      children: [new TextRun({ text: "Research team", bold: true })] } },
  });
  await fs.writeFile("output.docx", output);
}
main().catch(error => { console.error(error); process.exitCode = 1; });

Verify the output

After writing a .docx, render it and look at it:

mkdir -p preview
python scripts/office/soffice.py --headless --convert-to pdf --outdir preview output.docx
test -s preview/output.pdf
pdftoppm -jpeg -r 100 preview/output.pdf preview/page
ls preview/page-*.jpg   # then Read the images

Use a fresh preview directory or remove its old PDF first: converter exit status alone does not prove that a new file was written. Inspect every rendered page for overflow, headers, tables, and missing images; conversion can substitute unavailable fonts.

pdftoppm zero-pads page numbers to the width of the page count (page-01.jpg…page-12.jpg).

Editing existing documents

Legacy .doc files must be converted first: python scripts/office/soffice.py --headless --convert-to docx file.doc.

python - <<'PY'
import sys, zipfile
from pathlib import Path
sys.path.insert(0, "scripts")
from office.helpers import safe_extract
with zipfile.ZipFile("doc.docx") as archive:
    safe_extract(archive, Path("unpacked"))  # rejects symlinks and traversal
PY
python scripts/merge_runs.py unpacked/   # coalesce fragmented runs so text is findable
# edit unpacked/word/document.xml in place — do NOT reformat or pretty-print
(cd unpacked && rm -f ../out.docx && zip -Xr ../out.docx .)
python scripts/office/validate.py out.docx --original doc.docx   # bundled schema and package checks
# redlining? add --author "<the name you redlined under>" to check every edit is tracked

Word splits text across many <w:r> runs (revision ids, spell-check markers), so a phrase you can see in the document often doesn't exist as a contiguous string in the XML. merge_runs.py merges adjacent identically-formatted runs in word/document.xml while retaining text and formatting boundaries; render-check the result, especially fields and complex content; it also accepts a .docx directly (python scripts/merge_runs.py doc.docx -o merged.docx).

Tracked changes: preserve author/date/IDs and revisions that already exist. When redlining, validate with --author "<the name you redlined under>" (needs --original) — it compares body text after undoing new <w:ins>/<w:del> revisions, to expose untracked text edits that an accepted view can hide. Wrap runs in <w:ins>/<w:del> with w:id, w:author, w:date attributes. Inside <w:del>, the text element is <w:delText>, not <w:t>. A deleted paragraph mark (<w:pPr><w:rPr><w:del w:id=".." w:author=".." w:date=".."/></w:rPr></w:pPr>) means "merge this paragraph into the next" — so deleting a paragraph outright is that plus a <w:del> around every run. Within paragraph-mark w:rPr, place revision markers before the other run properties as required by that content model.

To produce a clean copy with all tracked changes accepted: python scripts/accept_changes.py in.docx out.docx.

The helper uses a temporary copy and isolated LibreOffice profile. Its own application macro opens the input with MacroExecutionMode=NEVER_EXECUTE, so document-supplied macros are disabled; it does not lower profile macro security. A timeout, conversion failure, or remaining revision elements in any Word XML part leaves the destination unchanged. --timeout 120 raises the limit per LibreOffice operation. A document without revision elements is copied without a LibreOffice round trip.

Accepting a deleted paragraph mark should join that paragraph to the next. Do not assume a Pandoc accepted-text view or LibreOffice conversion exactly reproduces Word's paragraph, list, or formatting semantics. Inspect deleted paragraph marks in the XML and render the clean copy, particularly deleted numbered paragraphs beside empty spacers. An unexpected empty bullet needs investigation, not automatic dismissal.

The bundled validator is a practical check against the shipped 2016 schemas plus selected Microsoft extensions, not a complete current Word compatibility verdict. --original suppresses inherited schema errors. --auto-repair rewrites the input and may change significant whitespace; inspect its changes. The redlining check covers body text only, not formatting, tables' structural revisions, or other stories.

Document-wide edit coverage

word/document.xml contains the main story, not all document text. Before a whole-document replacement, inventory the relevant header, footer, footnote, endnote, comment, and text-box stories through the package relationships. merge_runs.py processes only word/document.xml; it does not normalize those other parts. Apply the requested edit wherever its scope requires, preserve relationships, and check the rendered first-page and odd/even headers and footers as well as the body. See Microsoft's WordprocessingML structure.

Comments

Basic comments need a comments part, its relationship/content type, and a matching commentReference; range start/end markers optionally identify the text span. The helper additionally writes Microsoft extension parts for reply threading. Use it — directory mode when you'll also be editing document.xml (saves an unzip/rezip cycle), .docx-direct mode otherwise:

# Against an already-unpacked directory (preferred when also placing markers)
python scripts/comment.py unpacked/ "Fees & expenses cap is too low"
python scripts/comment.py unpacked/ "Agreed" --parent 0

# Against a .docx directly
python scripts/comment.py contract.docx "This cap is too low" -o annotated.docx

The script writes comments.xml, commentsExtended.xml, commentsIds.xml, commentsExtensible.xml, the relationships, and the content-type overrides. Comment IDs are auto-assigned; duplicate explicit IDs are rejected. Replies reference the last paragraph ID of the parent comment. Existing parts using alternate filenames require editing those relationship targets directly; the helper rejects them instead of creating competing comment parts. It then prints the <w:commentRangeStart>/<w:commentRangeEnd>/<w:commentReference> snippet to add to word/document.xml so the comment anchors to specific text — until you place those markers, the comment exists but is not visible.

Dependencies

docx (npm) · Python defusedxml and lxml · pandoc · LibreOffice (soffice) · pdftoppm (Poppler). Python package installation: python -m pip install defusedxml lxml in a dedicated environment. No credentials or service API calls are needed.

Reviewed against the current docx API, patchDocument, LibreOffice command line, Microsoft comments, reply paragraph IDs, and Pandoc options. Creation, placeholder patching, PDF rendering, comments, and revision acceptance were smoke-tested with docx 9.8.1, LibreOffice 26.2.4.2, Pandoc 3.11, and Poppler 26.09.0. Microsoft Word and Google Docs rendering were not tested.


This skill is created and maintained by Anthropic. Adapted here with frontmatter metadata and editing-scope guidance; see LICENSE.txt for terms.

FAQ

What does the docx skill do?

Creates, reads, edits, and manipulates Word documents (.docx files) or Word templates (.dotx files). Triggers include: any mention of 'Word doc', 'word document', '.docx', '.dotx', or requests to produce professional documents with formatting like tables of contents, headings, page numbers, or letterheads. Also use when extracting or reorganizing content from .docx or .dotx files, inserting or replacing images in documents, performing find-and-replace in Word files, working with tracked changes or comments, or converting content into a polished Word document. If the user asks for a 'report', 'memo', 'letter', 'template', or similar deliverable as a Word or .docx file, use this skill. Do NOT use for PDFs, spreadsheets, Google Docs, or general coding tasks unrelated to document generation.

How do I install docx?

Run npx skills add https://github.com/k-dense-ai/scientific-agent-skills --skill docx in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/docx/ (personal) or .claude/skills/docx/ (project).

Which AI agents can use docx?

Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.

Is docx safe to install?

No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.

Who maintains docx?

It is published by k-dense-ai in k-dense-ai/scientific-agent-skills. It has 1,818 recorded installs.

More from k-dense-ai/scientific-agent-skills

View all →

scientific-writing

k-dense-ai/scientific-agent-skills

Drafts, revises, and audits scientific manuscripts or reports with explicit evidence provenance, reporting-guideline coverage, authorship accountability, confidentiality controls, and local consistency checks. Use for manuscript sections, references, declarations, tables, figures, or submission preparation when scientific accuracy and traceability matter.

Education & Science2.4K installs

scientific-visualization

k-dense-ai/scientific-agent-skills

Creates and audits truthful, accessible, publication-ready scientific figures with Matplotlib, Seaborn, or Plotly. Use it for figure design, multi-panel layouts, uncertainty and missing-data displays, color/contrast review, image metadata validation, and journal export planning.

Education & Science2.4K installs

scientific-critical-thinking

k-dense-ai/scientific-agent-skills

Evaluates scientific claims and evidence quality. Applies to experimental design validity, biases and confounders, statistical interpretation, evidence grading frameworks (GRADE, Cochrane Risk of Bias), and teaching critical analysis. Supports evidence appraisal and identifying flaws; formal peer review writing belongs to peer-review.

Education & Science2.4K installs

literature-review

k-dense-ai/scientific-agent-skills

Conducts systematic, scoping, and narrative literature reviews using PubMed, arXiv, bioRxiv, Semantic Scholar, and other appropriate sources. Use for research synthesis, reproducible literature searches, screening, citation checking, or preparing Markdown and PDF reviews. Tracks search coverage, records versus studies, and evidence limitations; supports meta-analysis planning but does not supply a meta-analysis engine.

scientific-brainstorming

k-dense-ai/scientific-agent-skills

Facilitates evidence-aware scientific ideation with independent generation, structured discussion, explicit assumptions, transparent evaluation, adversarial review, and decision logs. Use for early-stage research brainstorming or prioritizing candidate directions; hand off empirical validation, study design, ethics or regulatory review, and clinical questions to appropriate experts or skills.

Education & Science2.3K installs

statistical-analysis

k-dense-ai/scientific-agent-skills

Guided statistical analysis for research data - test selection, assumption checking, effect sizes, power analysis, Bayesian alternatives, and APA-formatted reporting. Use whenever a user wants to compare groups, test a hypothesis, analyze experimental or survey data, check statistical assumptions, compute required sample sizes, or write up results - even if they never name a specific test. Covers t-tests, ANOVA, chi-square, correlation, regression, non-parametric and Bayesian methods. For low-level model APIs, see the statsmodels and pymc skills.

Testing & QA2.3K installs

Popular docs & writing skills

View category →

grill-with-docs

mattpocock/skills

A relentless interview to sharpen a plan or design, which also creates docs (ADR's and glossary) as we go.

Docs & Writing1.2M installs

lark-markdown

open.feishu.cn

飞书 Markdown:查看、创建、上传、编辑和比较飞书中的原生 Markdown 文件。当用户要操作飞书 Markdown 文件,或比较其远端版本及本地草稿时使用。纯本地 Markdown 文件操作不触发本 skill。不负责将 Markdown 导入为飞书在线文档,也不负责文件搜索、权限、评论、移动、删除等云空间管理操作。

Docs & Writing778.7K installs

writing-beats

mattpocock/skills

Writing, exploit; assemble raw material into a journey of beats, grounding each term before a beat leans on it.

Docs & Writing490.7K installs

writing-shape

mattpocock/skills

Writing, exploit: shape raw material into an article, paragraph by paragraph.

Docs & Writing490.2K installs

writing-fragments

mattpocock/skills

Writing, explore: mine raw fragments, no structure yet.

Docs & Writing489.6K installs

writing-for-agents

mattpocock/skills

Writing documents for agents. Use when creating or editing skills, or modifying AGENTS.md or CLAUDE.md.

Docs & Writing479.3K installs