# MarkItDown Setup Instructions

You are a setup assistant. The user has downloaded this file to set up MarkItDown — a tool that converts PDFs, Word docs, PowerPoints, and other files into Markdown, reducing Claude token usage by up to 90%.

**Follow these steps automatically without asking for confirmation unless something fails.**

---

## What You Are Setting Up

- A Python virtual environment with MarkItDown installed
- A `convert` folder where users drop files they want converted
- A `convert.py` script that converts all files in that folder to Markdown
- A `convert.bat` file they can double-click to run the conversion

All files will be created in the current working directory.

---

## Step 1 — Check Python

Run this command to verify Python is installed:

```
python --version
```

If Python is not installed, tell the user to download it from https://www.python.org and restart.

---

## Step 2 — Create Virtual Environment

Run:

```
python -m venv .venv
```

Then activate it:

- **Windows:** `.venv\Scripts\Activate.ps1`
- **Mac/Linux:** `source .venv/bin/activate`

If PowerShell blocks the script, run this first:
```
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
```

---

## Step 3 — Install MarkItDown

Run these commands:

```
pip install markitdown
```

Then install the optional extras (skip any that fail — they are not critical):

```
pip install python-pptx "mammoth~=1.11.0" pandas openpyxl xlrd lxml "pdfminer.six>=20251230" "pdfplumber>=0.11.9" olefile pydub SpeechRecognition azure-ai-documentintelligence "azure-ai-contentunderstanding>=1.2.0b1" azure-identity
```

> Note: If you are on Python 3.14+, `youtube-transcript-api` will fail to install — this is expected and can be ignored. Everything else works normally.

---

## Step 4 — Create the convert folder

Create a folder called `convert` in the current directory:

```
mkdir convert
```

---

## Step 5 — Create convert.py

Create a file called `convert.py` in the current directory with this exact content:

```python
from pathlib import Path
from markitdown import MarkItDown

INPUT_DIR = Path(__file__).parent / "convert"
OUTPUT_DIR = INPUT_DIR / "output"

def main():
    if not INPUT_DIR.exists():
        print(f"Folder not found: {INPUT_DIR}")
        return

    OUTPUT_DIR.mkdir(exist_ok=True)
    files = [f for f in INPUT_DIR.iterdir() if f.is_file()]

    if not files:
        print("No files found in convert/")
        return

    md = MarkItDown()

    for file in files:
        print(f"Converting: {file.name} ...", end=" ")
        try:
            result = md.convert(str(file))
            out_path = OUTPUT_DIR / (file.stem + ".md")
            out_path.write_text(result.text_content, encoding="utf-8")
            print(f"-> output/{file.stem}.md")
        except Exception as e:
            print(f"FAILED ({e})")

if __name__ == "__main__":
    main()
```

---

## Step 6 — Create convert.bat (Windows only)

Create a file called `convert.bat` in the current directory with this exact content:

```bat
@echo off
call "%~dp0.venv\Scripts\activate.bat"
python "%~dp0convert.py"
pause
```

For Mac/Linux users, create `convert.sh` instead:

```bash
#!/bin/bash
source "$(dirname "$0")/.venv/bin/activate"
python "$(dirname "$0")/convert.py"
```

Then make it executable:
```
chmod +x convert.sh
```

---

## Step 7 — Verify the Setup

Run the script to confirm everything works:

```
python convert.py
```

The expected output is:
```
No files found in convert/
```

This confirms the setup is working correctly.

---

## Setup Complete

Tell the user:

> ✅ Setup is complete! Here is how to use it:
>
> 1. Drop any PDF, Word, PowerPoint, or Excel file into the **convert** folder
> 2. Double-click **convert.bat** (Windows) or run **./convert.sh** (Mac/Linux)
> 3. Find your converted **.md** files in **convert/output/**
> 4. Attach the **.md** file to Claude instead of the original document
>
> This reduces token usage by up to 90% — a 37KB PDF becomes a 4KB Markdown file using ~985 tokens instead of ~9,275.
>
> **Supported formats:** PDF, Word (.docx), PowerPoint (.pptx), Excel (.xlsx/.xls), HTML, Outlook (.msg), audio files, and plain text.
