Sandbox
@evolsb/legal-redline-tools

Contract redline output tool for Claude Code

This repo turns a JSON list of contract edits into the files people actually send: tracked-changes `.docx`, redline PDFs, summary PDFs, internal memos, and markdown. It works as a CLI, a Python library, and a Claude Code skill, so an agent can do the review while this tool handles the deliverables.

57 stars6 forksPythonUpdated 1mo ago
Who it's for

Builders who want their agent to turn contract review into Word redlines and review PDFs.

What it delivers

You can move from contract analysis to counterparty-ready markup without manually recreating changes in Word.

What it does

Tracked-changes Word output

Writes a `.docx` with real accept/reject tracked changes.

Redline PDF generation

Renders the full document with inline deletions, insertions, change bars, and a summary page.

Summary and memo outputs

Creates a clean summary PDF for the other side and an internal memo with tiers, rationale, and walkaway positions.

Markdown export

Produces structured markdown for documentation or downstream agent workflows.

Document diff and remap

Compares two `.docx` files, generates redlines from differences, and remaps section references between versions.

Placeholder scanning

Finds blank fields, `$X`, `TBD`, and missing exhibit references in a contract.

How to get it

  1. 1From source
    git clone https://github.com/evolsb/legal-redline-tools.git
    cd legal-redline-tools
    pip install -e .
  2. 2Or directly from GitHub
    pip install git+https://github.com/evolsb/legal-redline-tools.git

README

legal-redline-tools

GitHub stars License: MIT Python 3.9+ Version

Generate tracked-changes Word docs and redline PDFs from a contract review — the same deliverables lawyers actually send.

Define your proposed changes as JSON. Get a tracked-changes .docx with real accept/reject markup, full-document redline PDFs, internal negotiation memos, and structured markdown. Pairs with claude-legal-skill for end-to-end AI contract review, or works with any agent or manual workflow.

The Problem

AI contract review is everywhere now. But every tool stops at analysis — a list of issues in a chat window. The lawyer on the other side doesn't want your AI's opinion. They want a marked-up Word file with tracked changes they can accept or reject, and a redline PDF they can print and read.

python-docx has refused to add tracked changes for 9 years. So AI tools are stuck behind a manual copy-paste wall: the agent finds the issues, then a human spends an hour transcribing them into Word's track changes by hand.

This tool eliminates that wall. Give it a .docx and a list of changes as JSON, and it produces everything — from the tracked-changes Word file your counterparty will review, to the internal negotiation memo your team will use to prepare.

How It Works

flowchart LR
    A["<b>AI Agent</b><br/>reviews contract<br/><i>(claude-legal-skill<br/>or any review agent)</i>"] -->|JSON redlines| B["<b>legal-redline-tools</b>"]
    B --> C["Tracked-changes .docx"]
    B --> D["Full-document redline PDF"]
    B --> E["Summary PDF"]
    B --> F["Internal negotiation memo"]
    B --> G["Structured markdown"]
  1. Review — An AI agent (like claude-legal-skill) analyzes the contract, identifies issues, and classifies them by tier
  2. Iterate — Discuss findings in chat, adjust positions, add walkaway thresholds
  3. Generate — The agent outputs a JSON array of redlines, and this tool produces all deliverables
  4. Send — External files go to the counterparty. Internal memo stays with your team.

Use Cases

  • SaaS vendor agreement — Vendor sends a 30-page MSA. You review it with an AI agent, negotiate liability caps and termination rights, and send back a tracked-changes Word doc with 15 proposed changes.
  • M&A due diligence — Reviewing a target's customer contracts. Diff the template against each signed version, flag deviations, generate a summary for the deal team.
  • Multi-party agreements — Tri-party or sub-licensing deals where you need consistent redlines across related agreements (main agreement, exhibits, sub-partner templates). Cross-agreement comparison catches inconsistencies.
  • NDA review — Quick turnaround. Agent flags non-mutual clauses and overbroad non-competes, you generate the markup in one pass.
  • Employment / consulting agreements — Review IP assignment, non-compete scope, termination provisions. Generate internal memo with walkaway positions before the negotiation call.

Output Examples

Full-Document Redline PDFSummary of ChangesInternal Negotiation Memo
Full-document redline PDF with inline strikethrough and change barsSummary PDF showing proposed changesInternal memo with tier-grouped analysis
Entire contract with inline red strikethrough, blue underline, and change barsClean schedule of proposed changes for the counterpartyTier-grouped analysis with rationale, walkaway positions, and precedent

Plus: tracked-changes .docx (real Word accept/reject) and structured markdown for AI pipeline chaining.

Capabilities

#FeatureDescription
1Tracked-changes .docxReal Word tracked changes (strikethrough + insertion) that recipients can accept/reject
2Full-document redline PDFEntire contract with inline markups, change bars, and summary page
3Summary PDFSchedule of proposed changes (external for counterparty, internal with rationale)
4Internal memo PDFTier-grouped analysis with rationale, walkaway positions, and precedent
5MarkdownStructured output for PRs, documentation, or AI pipeline chaining
6Document diffCompare two .docx files and auto-generate redlines from differences
7Section remappingRemap redline section references when switching document versions
8Cross-agreement comparisonCompare redline sets across related agreements for consistency
9Placeholder scannerFind blank fields, $X, TBD, and missing exhibit references

Install

From source:

git clone https://github.com/evolsb/legal-redline-tools.git
cd legal-redline-tools
pip install -e .

Or directly from GitHub:

pip install git+https://github.com/evolsb/legal-redline-tools.git

Quick Start

CLI

# Apply redlines from JSON and generate all outputs
legal-redline apply original.docx output.docx \
    --from-json redlines.json \
    --pdf full-redline.pdf \
    --summary-pdf summary.pdf \
    --memo-pdf internal-memo.pdf \
    --markdown redlines.md \
    --header "Proposed Redlines — Feb 2026"

# Inline changes (no JSON file needed)
legal-redline apply original.docx output.docx \
    --replace "old text" "new text" \
    --delete "text to remove" \
    --insert-after "anchor text" "new text"

# Compare two document versions
legal-redline diff original.docx revised.docx -o changes.json

# Scan for blank fields and placeholders
legal-redline scan contract.docx

# Remap section references to a new document
legal-redline remap old-agreement.docx new-agreement.docx \
    --redlines redlines.json -o remapped.json

# Compare redlines across agreements
legal-redline compare \
    --agreements msa=msa-redlines.json tri-party=triparty-redlines.json \
    -o comparison.md

Python API

from legal_redline import (
    apply_redlines, render_redline_pdf, generate_summary_pdf,
    generate_memo_pdf, generate_markdown, diff_documents,
    remap_redlines, compare_agreements, format_comparison_report,
    scan_document,
)

redlines = [
    {"type": "replace", "old": "20% of fees", "new": "100% of fees or $250K",
     "section": "7.2", "title": "Liability Cap", "tier": 1,
     "rationale": "20% is below market standard"},
    {"type": "delete", "text": "shall terminate without liability"},
    {"type": "insert_after", "anchor": "Effective Date",
     "text": ". 90-day termination right"},
    {"type": "add_section", "after_section": "Section 12",
     "text": "New audit rights clause...", "new_section_number": "12A"},
]

# Tracked-changes .docx
apply_redlines("original.docx", "output.docx", redlines)

# Full-document redline PDF
render_redline_pdf("original.docx", redlines, "redline.pdf",
                   header_text="Proposed Redlines")

# Summary PDF (external — clean, no rationale)
generate_summary_pdf(redlines, "summary.pdf",
                     doc_title="Merchant Agreement v3", mode="external")

# Internal memo PDF (tier-grouped analysis)
generate_memo_pdf(redlines, "memo.pdf", doc_title="Merchant Agreement v3")

# Markdown output
md = generate_markdown(redlines, doc_title="Agreement", mode="internal")

# Diff two documents → redlines JSON
changes = diff_documents("v1.docx", "v2.docx")

# Remap sections between document versions
updated, report = remap_redlines("old.docx", "new.docx", redlines)

# Cross-agreement comparison
result = compare_agreements({"msa": msa_redlines, "sow": sow_redlines})
print(format_comparison_report(result))

# Scan for placeholders
report = scan_document("contract.docx")

JSON Format

Redlines are a JSON array. Each entry has a type and type-specific fields, plus optional metadata for internal analysis.

Redline Types

TypeRequired FieldsDescription
replaceold, newFind and replace text with tracked change
deletetextDelete text as tracked deletion
insert_afteranchor, textInsert new text after anchor
add_sectiontext, after_sectionInsert new paragraph/section

Optional Metadata

FieldUsed InDescription
sectionAll outputsContract section reference (e.g. "7.2")
titleAll outputsHuman-readable title
tierInternal onlyPriority 1-3 (1=non-starter, 2=important, 3=desirable)
rationaleInternal onlyWhy the change is proposed
walkawayInternal onlyFall-back position
precedentInternal onlyMarket standard reference

See examples/sample-redlines.json for a complete example with all 4 types.

Output Modes

External (counterparty-facing) — Clean outputs with only the proposed changes. No rationale, tiers, or walkaway positions. This is what you send to the other side.

Internal (team-facing) — Full analysis with strategy context. Tier-grouped memos with rationale, walkaway positions, and precedent citations. Never send these to the counterparty.

Text Matching

Redline text fields (old, text, anchor) must match text in the document. The matching engine handles common mismatches automatically:

  • Smart quotes — Curly quotes normalized to straight quotes
  • Whitespace — Tabs, double spaces, and PDF conversion artifacts collapsed
  • Dashes — En-dashes and em-dashes treated as hyphens
  • Cross-run — Text split across bold/italic formatting runs matched as plain text

End-to-End Workflow with claude-legal-skill

claude-legal-skill handles the review side — risk detection, market benchmarks, position-aware analysis. This tool handles the output. Together:

# 1. Install the review skill
git clone https://github.com/evolsb/claude-legal-skill ~/.claude/skills/contract-review

# 2. Install this tool
pip install git+https://github.com/evolsb/legal-redline-tools.git

# 3. Review a contract (skill analyzes and outputs JSON redlines)
#    "Review this MSA - I'm the vendor"

# 4. Generate all deliverables from the redlines
legal-redline apply original.docx redlined.docx \
    --from-json redlines.json \
    --pdf full-redline.pdf \
    --summary-pdf summary.pdf \
    --memo-pdf internal-memo.pdf

Or use this tool standalone — it works with any AI agent or manual workflow. Just produce the JSON format above.

To use the included redline-generation skill with Claude Code:

mkdir -p ~/.claude/skills/contract-redline
cp skill.md ~/.claude/skills/contract-redline/skill.md

Limitations

  • Text matching — Redline anchors must match document text; heavily reformatted or PDF-converted documents may need manual text cleanup
  • Complex formatting — Tables, images, and nested lists are preserved but not targeted by redlines
  • Character support — PDF outputs use Latin-1 encoding; non-Latin scripts (Cyrillic, CJK, Polish diacritics) may render as ? in PDFs (.docx output is unaffected)
  • Large documents — Works on 100+ page contracts but PDF generation is slower

Credits

  • python-docx — Word document manipulation
  • fpdf2 — PDF generation
  • lxml — XML processing for OOXML tracked changes

Next Steps

License

MIT


Built by Chris Sheehan.

Files in the repo

Repository payload10 top-level entries
  • assets
  • examples
  • legal_redline
  • tests
  • .gitignore
  • CHANGELOG.md
  • LICENSE
  • pyproject.toml
  • README.md
  • skill.md

Discussion (0)

Ask about usage, or say what you built with it

Sign in to join the discussion.

No comments yet. Be the first to say what this is good for.

More tools

MemPalace/
mempalace

The best-benchmarked open-source AI memory system. And it's free.

59k
virgiliojr94/
book-to-skill

Turn any technical book PDF into a Claude Code skill — ready to study, reference, and use while you work.

30k
sickn33/
agentic-awesome-skills

AAS Core is the local, agent-first control plane for complete catalog discovery, agent-owned selection, stack validation, and planning, backed by 2,115+ agentic skills. Includes CLI, local MCP, catalog, plugins, and Workbench.

46k
iOfficeAI/
OfficeCLI

OfficeCLI is the first and best Office suite purpose-built for AI agents to read, edit, and automate Word, Excel, and PowerPoint files. Free, open-source, single binary, no Office installation required.

30k
googleworkspace/
cli

Google Workspace CLI — one command-line tool for Drive, Gmail, Calendar, Sheets, Docs, Chat, Admin, and more. Dynamically built from Google Discovery Service. Includes AI agent skills.

31k

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

155k