
DOCX Shell Workaround
Handle docx files using shell-based XML extraction and python-docx via run_shell when...
Install
npx skills add HKUDS/AgentPilot --skill docx-shell-workaround -g -a claude-code -y- Repository
- HKUDS/AgentPilot7.8k
- Category
- Documents
- Updated
- 3d ago
- License
- MIT
- Context cost
- Lightabout 1,253 tokens
- Runs scripts
- No, instructions only
What it does
Handle docx files using shell-based XML extraction and python-docx via run_shell when standard tools fail
DOCX Shell Workaround
When to Use
Use this skill when:
read_filecannot extract content from .docx filesexecute_code_sandboxencounters failures when creating or modifying docx files- You need a reliable fallback for docx file manipulation
Reading DOCX Files
Step 1: Extract document.xml using unzip
Use run_shell to unzip the .docx file (which is a ZIP archive) and extract the main document XML:
unzip -p input.docx word/document.xml > document.xml
Step 2: Parse XML with ElementTree via run_shell
Extract text content by parsing the XML. Use run_shell to execute Python code:
python3 << 'EOF'
import xml.etree.ElementTree as ET
tree = ET.parse('document.xml')
root = tree.getroot()
namespace = {'w': 'http://schemas.openxmlformats.org/wordprocessingml/2006/main'}
text_content = []
for elem in root.iter():
if elem.tag.endswith('t'):
if elem.text:
text_content.append(elem.text)
text = ''.join(text_content)
print(text)
EOF
Step 3: Optional - More robust XML parsing
For better text extraction that handles paragraphs:
python3 << 'EOF'
import xml.etree.ElementTree as ET
tree = ET.parse('document.xml')
root = tree.getroot()
ns = {'w': 'http://schemas.openxmlformats.org/wordprocessingml/2006/main'}
paragraphs = []
for p in root.findall('.//w:p', ns):
para_text = []
for t in p.findall('.//w:t', ns):
if t.text:
para_text.append(t.text)
if para_text:
paragraphs.append(''.join(para_text))
for para in paragraphs:
print(para)
EOF
Creating DOCX Files
Use python-docx via run_shell (NOT execute_code_sandbox)
When execute_code_sandbox fails for docx operations, use run_shell instead:
python3 << 'EOF'
from docx import Document
from docx.shared import Inches, Pt
from docx.enum.text import WD_ALIGN_PARAGRAPH
doc = Document()
# Add heading
doc.add_heading('Document Title', 0)


