claude-docx-generator
v1.0.0
Published
Turn JavaScript that builds a docx Document into a real .docx file — without editing file paths. Paste AI-generated docx code and run.
Maintainers
Readme
DOCX Generator — Paste & Produce
Turn JavaScript that builds a docx Document into a real .docx file — without editing file paths.
Why this Exists:
Scenario: Claude Timed Out, But the DOCX Still Needs to Exist
You're working with an AI assistant to generate a 40-page report, proposal, thesis draft, or technical document.
The AI successfully writes the JavaScript that builds the DOCX using the docx package:
const { Document, Packer, Paragraph } = require("docx");
// hundreds of lines of generated content...But then one of these things happens:
- The AI session times out before producing the actual
.docxfile. - The generated script contains an environment-specific path such as
/mnt/data/report.docx. - The code came from Claude, ChatGPT, Gemini, or another platform that saved files to a location that doesn't exist on your machine.
- You just want the document now—not another round of path fixing and debugging.
Instead of editing file paths throughout the script, you paste the generated code into paste_here.js and run:
node paste_here.jsThis tool automatically intercepts the DOCX file write operation and redirects the output into the local outputs/ directory.
The result: AI-generated DOCX code becomes a real .docx file on your computer in seconds, regardless of where the original script expected to save it.
In short: when an AI can generate the document code but cannot deliver the document itself, this repository bridges the gap.
Badges & quick facts
- No publish required: this is a local tool — run with Node.js.
- Safe outputs:
outputs/is in.gitignoreso generated DOCX files won't be committed accidentally.
Quick start
- Install dependencies:
npm installPaste your docx-generating code into paste_here.js.
paste_here.jsalreadyrequires runner.js which redirects Buffer writes intooutputs/.Run:
node paste_here.js
# or
npm run pasteFile references
- paste_here.js — development template where you paste code.
- runner.js — intercepts
fs.writeFileSync/fs.writeFileBuffer writes and redirects them intooutputs/. - generate2.js and generate2_to_docx.js — example generators present in the repo.
How it works (brief)
- Many
docxscripts follow the pattern:
Packer.toBuffer(doc).then(buffer => fs.writeFileSync('/some/absolute/path/my.docx', buffer));runner.jsmonkey-patchesfs.writeFileSyncandfs.writeFileat runtime. When the patched functions detect a Buffer (thedocxpayload), they replace the destination path withoutputs/<basename>so you don't have to edit the original code.
Best practices
- Keep
outputs/small — it contains generated binary files and is git-ignored. - If your pasted script writes streams, custom promises, or uses other FS APIs, open an issue or ask me to extend
runner.jsto catch that pattern.
Examples
- To test quickly, run the included example:
node generate2.js- The example will write
MIT_Masterclass_Geometry_of_Meaning.docxintooutputs/.
Contributing
- This is a tiny local tool. If you want features such as a CLI argument for destination, stream interception, or previewing generated docx, tell me which feature and I will add it.
License
- No license specified. Add a
LICENSEfile if you want to open-source this project.
