OfficeCLI-rust
CLAUDE.md19 starsChanged 6 months agoApache-2.0View on GitHub
OfficeCLI is a single-binary, pure-Rust CLI for creating, reading, modifying, and rendering Office documents (.docx, .xlsx, .pptx) and PDFs. No Office installation needed. It also includes an MCP server for AI agent integration and a watch server for live HTML previews. Tests are inline (#[test] within source files), not in separate tests/ directories. No integration tests exist. Cargo workspace with 7 crates under crates/: Dependency graph: handler-common is the root trait crate. oxml depends on handler-common. OOXML handlers depend on…
In this repository14 other files it gives its agents.
- AGENTS.mdAGENTS.md
- officecliSkill
- morph-ppt-3dSkill
- morph-pptSkill
- officecli-academic-paperSkill
- officecli-data-dashboardSkill
- officecli-docxSkill
- officecli-financial-modelSkill
- officecli-pdfSkill
- officecli-pitch-deckSkill
- officecli-pptxSkill
- officecliSkill
- officecli-word-formSkill
- officecli-xlsxSkill
The file
We split this CLAUDE.md into the rules it gives an agent
7 rules. About 0 are common, 2 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 44
All handlers implement the same DocumentHandler trait with three layers:
- Distinctive: line 50
Always prefer higher layers.
- Very specific: line 54
Interior mutability: All handlers use RefCell (RefCell<OxmlPackage> or RefCell<PdfReader>) because DocumentHandler trait methods take &self.
- Distinctive: line 57
TextOffsetMap: Every format emits full text + character-offset-to-path-ID mapping for AI agents to precisely locate and modify text.
- Very specific: line 97
Always quote paths with brackets in shell: '/slide[1]' to avoid zsh/bash glob expansion.
- Very specific: line 98
All attributes go through --prop key=value, not separate --name flags.
- Very specific: line 99
When unsure about property names or command syntax, use the help system: officecli help <format> <element> rather than guessing.
≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
OfficeCLI is a single-binary, pure-Rust CLI for creating, reading, modifying, and rendering Office documents (.docx, .xlsx, .pptx) and PDFs. No Office installation needed. It also includes an MCP server for AI agent integration and a watch server for live HTML previews.
Build & Development Commands
cargo build # Debug build
cargo build --release # Release build
cargo check # Fast compile check (no binary)
cargo test # Run all tests (inline unit tests only, no integration test dirs)
cargo clippy --all-targets -- -D warnings # Lint
cargo fmt -- --check # Check formatting
cargo fmt # Auto-fix formatting
cargo run -- <ARGS> # Run with CLI args
make smoke # Smoke test: create + view a doc, verify binary works
make lint # fmt + clippy combinedTests are inline (#[test] within source files), not in separate tests/ directories. No integration tests exist.
Workspace Structure
Cargo workspace with 7 crates under crates/:
| Crate | Purpose |
officecli | CLI binary (entry point) |
handler-common | DocumentHandler trait + shared types (DocumentNode, HandlerError, PathSegment, TextOffsetMap, etc.) |
oxml | OOXML ZIP package abstraction (OxmlPackage — open, read/write parts, content types, relationships) |
docx-handler | WordHandler — Word DOM (WordDom/WordNode) over OxmlPackage |
xlsx-handler | ExcelHandler — workbook model (WorkbookModel/Cell) over OxmlPackage |
pptx-handler | PptxHandler — presentation/slide XML over OxmlPackage |
pdf-handler | PdfHandler — separate backend (lopdf, custom content stream parser, font embedder, modifier) |
Dependency graph: handler-common is the root trait crate. oxml depends on handler-common. OOXML handlers depend on oxml. pdf-handler depends only on handler-common. officecli depends on all handlers.
Three-Layer Architecture
All handlers implement the same DocumentHandler trait with three layers:
- L1 (Semantic/Read):
viewmodes (text, annotated, outline, stats, issues, html, svg) - L2 (DOM/Query):
get,query,set,add,remove,move— path-based element operations - L3 (Raw):
raw,raw-set,validate— direct XML/XPath access
Always prefer higher layers. L2 handles structured edits; L3 is for cases L2 can't express.
Key Architectural Patterns
- Interior mutability: All handlers use
RefCell(RefCell<OxmlPackage>orRefCell<PdfReader>) becauseDocumentHandlertrait methods take&self. - Parse-modify-serialize: OOXML handlers parse XML into a custom DOM tree, mutate it, serialize back to XML string, then write back to the ZIP package.
- Path-based addressing: XPath-like paths with 1-based indexing (e.g.,
/body/p[3],/slide[1]/shape[@id=550950021]). Alias resolution built in (e.g., "paragraph" → "p"). - TextOffsetMap: Every format emits full text + character-offset-to-path-ID mapping for AI agents to precisely locate and modify text.
- Inline templates: Blank document creation uses hardcoded XML strings, no external template files.
- Platform conditional: Resident mode (Unix Domain Socket IPC) is Unix-only; stubbed with error on other platforms.
Handler Module Structure
Each handler crate follows a consistent module pattern:
handler.rs—DocumentHandlertrait impl + XML parse/serializedom_types.rs— Format-specific DOM types and element enumsnavigation.rs— Path parsing and DOM tree navigationmutations.rs—set,move,removeoperationsadd.rs—addelement operationsview.rs— View mode implementationsquery.rs— CSS-like selector queryraw.rs— Raw XML read/writehtml_preview.rs— HTML rendering for watch/previewtext_offset.rs—extract_text_with_offsets
Format-specific extras: docx has para_id.rs, helpers.rs; xlsx has formula_eval.rs; pptx has svg_preview.rs; pdf has content_stream.rs (~108KB parser/modifier), font_embedder.rs, modifier.rs, reader.rs, render.rs, text_extract.rs.
CLI Entry Point
crates/officecli/src/main.rs — clap-based CLI. open_handler() routes by file extension (.docx → WordHandler, .xlsx → ExcelHandler, .pptx → PptxHandler, .pdf → PdfHandler). Commands are defined in crates/officecli/src/commands/mod.rs.
Additional modes:
- Resident mode: Background IPC server via Unix Domain Socket (auto-starts on first access, 60s idle)
- Watch mode: Axum HTTP server for live HTML preview (default port 26315)
- MCP server: Stdio-based JSON-RPC 2.0 server exposing 13 tools
Contribution Rules
From CONTRIBUTING.md — two hard rules:
- One PR = one atomic change. Cannot be further decomposed. If a diff can be split into multiple independent PRs, submit each separately.
- Every PR must include a verifiable validation method. Bug fixes: officecli command sequence showing before/after. Features: screenshot + command sequence.
Important Conventions
- Paths are 1-based (XPath convention), but
--indexis 0-based (array convention). Excel row/col--indexis 1-based (OOXML convention). - Always quote paths with brackets in shell:
'/slide[1]'to avoid zsh/bash glob expansion. - All attributes go through
--prop key=value, not separate--nameflags. - When unsure about property names or command syntax, use the help system:
officecli help <format> <element>rather than guessing.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

