usps-ops
| Piece | Deliverables |
|---|---|
| Letter | letter .docx + envelope .docx with postage |
| Postcard | one postcard .docx (message + postage) |
Every stamped piece also gets: the stamps.com PDF renamed (Postage) - <stamps IMb>.pdf, and a line in tracking.dat.
Workflow
- Message. Draft it with him. For a letter, build the letter
.docxfrom the letterhead. - Postage. He buys it on stamps.com and attaches the PDF.
- Take three things from the PDF:
- the USPS-normalized recipient address;
- the postage indicia image;
- stamps.com's IMb, which you need only for its routing digits.
- Make our IMb. It keeps the same routing, but uses his MID and his next serial. It replaces stamps.com's barcode on the piece. USPS no longer lets his MID track pieces under stamps.com's MID; under his own MID he can.
- Build the piece from the envelope (#6 or #10) or postcard template:
- indicia → stamp box;
- our barcode → barcode slot;
- address → address block;
- for a postcard, the message as well.
- Preview, then deliver the files under his naming convention. He does the final polish in Word and prints.
- Log our IMb to
tracking.dat.
Setup
SK="$(ls -1dt /mnt/skills/*/usps-ops ~/.claude/skills/synced/*/usps-ops 2>/dev/null | head -1)"; echo "$SK"
Shell variables die between bash calls: re-run that line at the top of any call that uses $SK. Work in /tmp/usps.
Dropbox
Read through the Dropbox connector. For binaries, get a download_link and curl -sSfo <file> "<url>" it once — the URL is single-use, so never open or preview it first.
- Templates:
/Custom Office Templates/—Letterhead (US).dotx,Postcard.dotx,Envelope #10 (USPS).dotx,Envelope #6 (USPS).dotx. Always fetch fresh; never reuse a copy from an earlier conversation. - Finished mail:
/Sent Mail/ - Tracker:
/QuickLetterTracker/tracking.dat. Never touchprefs.datorqlprefsbeside it.
The connector cannot upload binaries, but it can move them. Put each .docx/.pdf into Sent Mail in two steps:
cfs upload /outbox/<file> --from <local file> --new(the durable filesystem;session-initsets it up).- Connector
movefrom/Apps/louietyj-claude-ai/outbox/<file>to/Sent Mail/<file>. He approves each move.
If cfs isn't available or he declines a move, deliver those files as downloads (save them to /mnt/user-data/outputs/) and tell him to drop them in Sent Mail.
Naming
YYYY-MM-DD - <Recipient> - <Subject> is the stem, e.g. 2026-10-02 - Acme - Arbitration opt-out. List /Sent Mail/ and match how earlier pieces to the same kind of recipient were named.
<stem>.docx— letter<stem> (Postage) - <stamps.com IMb>.pdf— his stamps.com PDF, renamed<stem> (Envelope) - <our IMb>.docxor<stem> (Postcard) - <our IMb>.docx
Writing the message
Draft with him; he approves the wording before you build anything. Letters are dated like 2 Oct 2026 and address the recipient in normal case, as written in their terms (the USPS-normalized form is only for the envelope).
Reading the stamps.com PDF
Assume nothing about its layout. Output varies with the stamps.com product and with how he saved it, and the scripts below are primitives, not a parser. Look at the page first (pdftoppm -r 100 -png), then work out where each piece is.
- Recipient address. Copy the lines stamps.com printed verbatim, because they are the USPS-normalized form (e.g.
KNG OF PRUSSA PA 19406-2608). Exception: if he shortened the recipient so stamps.com would accept it (e.g. dropped ac/oline), restore his original name/attention lines in UPPERCASE. Keep the street line and city/state/ZIP line exactly as printed. - Indicia. The postage block: amount,
US POSTAGE, mail class, date, and a 2-D code. It goes on the piece exactly as stamps.com produced it, so extract it losslessly. Never redraw it. - stamps.com IMb. 65 bars, each
F/A/D/T(full, ascender, descender, tracker), that decode to 31 digits. The last 11 are the routing: ZIP5 + ZIP4 + delivery point. That's all you need from it.
pdftotext -layout postage.pdf - # the text, in reading order
python3 "$SK/scripts/stamps_pdf.py" inspect postage.pdf # images, rows of thin rects, text lines, with positions
python3 "$SK/scripts/stamps_pdf.py" imb postage.pdf [--row I | --bbox x0,top,x1,bottom]
python3 "$SK/scripts/stamps_pdf.py" image postage.pdf <index> /tmp/usps/indicia # lossless extract
python3 "$SK/scripts/stamps_pdf.py" crop postage.pdf x0,top,x1,bottom out.png # render a region
python3 "$SK/scripts/imb.py" decode <65 FADT letters>
inspectcoordinates are PDF points from the top-left, after the page's rotation and before its cropbox. A viewer orpdftoppmapplies the cropbox, so its positions can be offset. To check what a region really contains,cropit and look.imbwith no options needs exactly one row of 65 vector bars.--bboxreads bars from pixels in a tight box around the barcode instead; it works for images, glyphs, anything rendered.- A barcode set in the IMb font shows up as a 65-letter FADT text line. Decode that text directly.
imagewrites a JPEG byte-for-byte, and any other format as a lossless PNG. If the indicia isn't a single embedded image,cropits region at 600 dpi.
When none of these fit, write your own code. pdfplumber, pypdfium2, poppler and PIL are all available. If you can't get a decode you trust, ask him for the IMb from his stamps.com receipt. Never guess digits.
Checks:
- ZIP+4. The decoded routing's ZIP+4 should equal the ZIP+4 in the recipient address:
55117560310goes withSAINT PAUL MN 55117-5603. 73 of his 74 past pieces matched. In the one that didn't, the address said20850-4302and the barcode said20850-4304. On a mismatch, first rule out a misread by decoding another way. If the barcode really differs, tell him and let him choose. - Other fields. Past stamps.com IMbs all had barcode ID
00, STID040, and a MID from206238to206241. Mention anything else. - Indicia. Look at the extracted image before using it.
Our IMb
- Serial. Download
tracking.dat, list/Sent Mail/, and save the names to a file. Thenpython3 "$SK/scripts/next_serial.py" tracking.dat listing.txt. It refuses to guess if it finds nothing — don't override that. Automates: the highest serial under MID903429007found in either source, + 1. Never reuse a serial. - Build.
python3 "$SK/scripts/imb.py" build <serial> <routing>. Automates:00+ STID310+903429007+ 6-digit serial + routing. STID 310 means Basic First-Class Mail, no address correction, IV tracking. Don't copy stamps.com's040: it requests manual address correction, which needs a printed endorsement. - Bars.
python3 "$SK/scripts/imb.py" encode <our IMb>. Automates: the USPS encoding (CRC + codeword tables) inimb_core.py. Never produce bars any other way. Always round-trip withimb.py decode.
Which envelope (#6 or #10). Use what he said. If he didn't say, ask.
Building the piece
python3 "$SK/scripts/fill_template.py" template.dotx out.docx spec.json
{
"text": {"ADDRESS": ["ACME", "C/O REGISTERED AGENT, INC.", "1010 DALE ST N", "SAINT PAUL MN 55117-5603"],
"CONTENT": ["Hello,", "", "Name:\tLouie Tan"]},
"font_size": {"CONTENT": 9},
"barcode": "FADT…",
"stamp": "/tmp/usps/indicia.jpg"
}
Automates: a new .docx from the template, with each <NAME>/<<NAME>> placeholder filled:
- the indicia image goes in the stamp box, 1.54" wide, as on his past pieces;
- our bars go in the barcode slot, set in the
USPSIMBStandardfont; - the address lines and the message go in as one paragraph per list item (
""is a blank line,\ta tab).
The letterhead's date and recipient fields are filled as DATE and RECIPIENT. font_size is the only formatting applied; layout is left alone. The script fails if a placeholder is left unfilled, or if the spec names one it can't find, e.g. because he edited the template. In that case, open the template, see what changed, and fill it yourself.
Verify, then deliver
bash "$SK/scripts/preview.sh" /tmp/usps/preview out1.docx out2.docx
Automates: installing the bundled fonts (Figtree, USPSIMBStandard), then running soffice → PDF → pdftoppm. Without those fonts the barcode renders as letters. LibreOffice only approximates Word, so judge content and placement, not exact line breaks.
Check:
- the stamp is in its box;
- the barcode renders as bars;
imb.py decode <the bars you inserted>equals our IMb.
Then put the deliverables, including the renamed postage PDF, in Sent Mail under their final names (see Dropbox) and list them for him.
He does the final polish in Word. Point out layout problems you can see, such as an address line that wraps or postcard text cut off at the bottom. Fix them only if he asks you to polish. If he does, the fixes are your call: a smaller font_size (his postcards have used 9pt text), shorter wording, or a wider text box.
Logging to tracking.dat
After he has the files:
python3 "$SK/scripts/tracking_dat.py" tracking.dat <our IMb> "<RECIPIENT SHORT NAME>" [YYYY-MM-DD]
The name is the stem's recipient, e.g. ACME.
Automates: prepending M/D/YYYY<TAB>zip9<TAB>dpc<TAB>tracking20<TAB>RECIPIENT (no zero padding, CRLF endings, newest first), and refusing duplicates.
Writing it back means replacing the file through the connector:
- Tell him the exact line being added.
deletethe old file. That moves it to Dropbox's deleted files, so it's recoverable.create_fileat the same path with the new full content, keeping\r\nline endings.- Download it again and
cmpit with your local copy. If they differ, say so and stop.