Keep one authoritative copy of a plan, and don't maintain an HTML version and a Markdown version by hand side by side. For artifacts people mostly review in a browser, I keep the HTML as the source and generate Markdown when an agent needs it. Generating one from the other is fine. Editing both is where it goes wrong.
Most of the plans and reports my agents write for me are HTML now, and I'm not the only one. Thariq Shihipar's post on the Claude Code blog, The unreasonable effectiveness of HTML, argues that "the chance of someone actually reading your spec, report, or PR writeup is much higher if it's in HTML". That matches my experience sending plans to developers. The Hacker News thread on it pushed back, fairly: one commenter settled on "HTML for deliverables, Markdown for infrastructure", and another said Markdown is "a much better fit than HTML for loading context."
Both sides are right. People read the HTML. Agents pay for every class="..." in it. So the question is which one you keep, and how the other one gets made.
Why hand-kept copies drift
Say you ask the agent to write plan.html and a matching plan.md. The first draft is fine. Then you ask for a change, "move the migration before the flag cut-over", and the agent edits the HTML, because that's the file you're both looking at. The Markdown is now wrong and nothing tells you. Two weeks later a fresh session reads plan.md and does the old order.
That's the failure: two copies that both get edited by hand. It isn't "Markdown first is wrong". If your plans are mostly prose and your team edits them line by line in PRs, Markdown as the source with HTML rendered from it is a perfectly good setup. It just has Markdown's ceiling. The side-by-side comparison, the diagram and the risks table with colour are the reasons to use HTML in the first place, and they don't survive a round trip through Markdown.
For artifacts people review in a browser and approve, I flip it. The HTML is what someone said yes to, so it's the version of record. The Markdown is generated from it when an agent needs it.
A real example, start to finish
To check this holds up, I wrote a small, made-up migration plan as an agent would: one HTML file with inline CSS, tabs driven by a few lines of JS, a risks table and an SVG bar chart. Then I ran it through Turndown with the script below and wrote down the exact instruction the next agent gets. All the files are here so you can check them:
- migration-plan.html, the plan as a person sees it
- migration-plan.md, the exact Turndown output
- to-md.mjs, the script
The script
The script below is the baseline used for the measured example. For new handoffs, save the updated v2 script as to-md-v2.mjs in your project root. It adds URL allowlists, serialized form-field values and embed markers. The conversion tests explain its remaining losses.
You need Node and two packages:
npm i turndown@7.2.4 turndown-plugin-gfm@1.0.2
Save this as to-md.mjs in your project root:
// to-md.mjs - usage: node to-md.mjs plans/plan.html > /tmp/plan.md
import { readFileSync } from "node:fs";
import TurndownService from "turndown";
import { gfm } from "turndown-plugin-gfm";
const td = new TurndownService({ headingStyle: "atx", codeBlockStyle: "fenced" });
td.use(gfm); // tables, strikethrough
td.remove(["script", "style", "title"]); // the agent doesn't need your tab-switching JS
// Keep the link text, drop javascript: and data: URLs.
td.addRule("unsafeLinks", {
filter: (node) =>
node.nodeName === "A" &&
/^\s*(javascript|data):/i.test(node.getAttribute("href") || ""),
replacement: (content) => content,
});
process.stdout.write(td.turndown(readFileSync(process.argv[2], "utf8")).trim() + "\n");
The unsafeLinks rule matters. Without it, Turndown keeps <a href="javascript:alert(1)">the dashboard</a> as a live javascript: link in the Markdown. With it you get the words "the dashboard" and no URL. I tested both with Turndown 7.2.4.
Then add this to AGENTS.md, with your real file name:
Plans live in plans/*.html. Before starting a task that mentions a plan, run
`node to-md-v2.mjs plans/sessions-to-postgres.html > /tmp/plan.md` and read /tmp/plan.md,
not the HTML.
Write the output to a temp path, not next to the HTML. Once you commit the .md, you have two copies again.
What came out
This is the full output of the original baseline command, node to-md.mjs migration-plan.html, unedited:
# Plan: move sessions from Redis to Postgres
We move login sessions out of Redis and into a `sessions` table in Postgres, so we can drop the Redis instance. The move runs behind the `sessions_pg` flag with a dual-write period. While both stores remain current, turning the flag off restores Redis reads. After Redis writes stop, rollback requires restoring and resynchronizing Redis; the flag alone is no longer enough.
Migration order Risks Open questions
## Migration order
1. Add the `sessions` table and its index on `expires_at`. No app changes yet.
2. Ship dual-write: every new or refreshed session goes to Redis and Postgres. Reads stay on Redis.
3. Wait 14 days, the max session lifetime, so every live session exists in both stores.
4. Turn on `sessions_pg` for reads, 10% of users first, then everyone.
5. Stop writing to Redis. Remove the Redis client and the instance a week later.
Do not flip reads before step 3 is done. Sessions created before dual-write only exist in Redis.
## Risks
| Risk | Severity | Mitigation |
| --- | --- | --- |
| Reads flipped before old sessions are copied, users get logged out | High | Gate step 4 on the 14-day wait, not on a date |
| Expired rows pile up in `sessions` | Medium | Nightly delete where `expires_at < now()` |
| Extra write load on the primary during dual-write | Medium | Watch the chart below before going past 10% |
Primary writes/sec Today Dual-write 10% reads 100% reads
## Open questions
* Do we keep "remember me" sessions at 14 days, or is that the moment to shorten them?
* Who owns the nightly cleanup job, the API team or infra?
* Is the 10% read cohort random, or internal accounts first?
The parts the next agent actually needs made it: the five steps in order, the "don't flip reads before step 3" warning, the risks table with severity and mitigation, and all three open questions. The tabs only hid and showed sections that were already in the markup, so nothing was lost there. You just get one stray line, "Migration order Risks Open questions", where the tab buttons were.
The token difference on this file, counted with tiktoken 0.14.0 and the o200k_base encoding: 1,488 tokens for the HTML, 401 for the Markdown. Other models use other tokenizers, so treat that as a rough guide for this one file, not a rule.
What broke
The chart. In the browser it's four bars, and the last one is red and much taller: write load on the primary jumps when reads move to Postgres. That's the most important thing on the risks tab. In the Markdown it became one line of axis labels:
Primary writes/sec Today Dual-write 10% reads 100% reads
No values, no red bar, and the risks table still says "Watch the chart below", pointing at nothing. An agent working on step 4 has no idea there's a problem.
The fix is in the HTML, not the converter. I wrapped the chart in a <figure> and added a <figcaption> with the numbers (captioned HTML, its output). The caption comes through as a normal paragraph:
Primary writes/sec from the staging load test: today 400, dual-write 550, 10% reads 900, 100% reads 1,300. The red bar is over our 1,000 writes/sec budget, so step 4 needs a bigger primary or batched session refreshes before it goes past 10%.
The numbers are made up, like the rest of the plan. The point is that they now reach the agent.
The instruction to the next agent
With the AGENTS.md line above in place, this is what I'd type in the next session, in whichever agent:
Read the sessions-to-postgres plan (convert it first, per AGENTS.md).
Before writing code, list the migration order, the risks and the open questions
you found in it. Then do step 1 only.
Asking it to list the order, risks and questions first is a cheap way to see what it actually got from the conversion before it starts changing things.
What survives conversion, and what doesn't
Conversion isn't lossless, and the example shows where. Headings, paragraphs, lists, links, code and simple tables come through well. That's most of a plan or a QA report. The rest:
- Anything rendered by JavaScript. If the agent builds a table with a script at load time, a static converter sees an empty
<tbody>. Turndown doesn't run scripts, and it shouldn't. Ask for the data in the markup and use JS only for behaviour, like the tabs above. - Charts and diagrams. As above: an SVG turns into its text labels at best. Give every chart a caption or a small table.
- Meaning carried by layout. A two-column "before / after" comes out as two blocks one after the other. If the labels were in the CSS, they vanish. Headings beat visual position.
- Stray Markdown syntax in plain text.
the *real* fixor__init__.pywould turn into emphasis. Turndown backslash-escapes Markdown characters by default, and its README warns the rules "can be quite aggressive." If you roll your own converter, check what yours does.
On safety: you're feeding agent-written content to another agent. The script above strips scripts and styles and drops javascript: and data: links. It doesn't cap time or memory, so if you run it on files you don't trust, run it in a worker or a container with limits. A pathological 10 MB HTML file shouldn't be able to hang anything.
For twelve harder cases, see what survives HTML to Markdown conversion.
A prompt pattern that makes both sides happy
Most of the "HTML is bad context" problem is avoidable when the HTML is written. Here's the block I'd add to AGENTS.md or CLAUDE.md:
When you write an HTML artifact (plan, report, review):
- One self-contained file. Inline CSS. No external fonts or CDNs.
- Real semantic structure: h1/h2/h3, ul/ol, table, pre/code.
- Put data in the markup, not in JS that builds the DOM.
- Every chart or diagram gets a figcaption and, where it has numbers, a small table.
- Start with a 3 to 5 line summary paragraph under the h1.
The first thing an agent reads after conversion is the summary, and a good summary makes the other conversion problems smaller.
Where Factrove fits
I'm testing this get-by-ID workflow in an unreleased local Factrove prototype. The prototype stores HTML and generates Markdown on request without saving the Markdown. This is what I run locally:
pnpm factrove get <artifact-id> --format markdown
In that prototype, omitting --format or passing html returns the original bytes. Its converter filters javascript: and data: links and runs in a worker with a time limit and a worker-heap limit. The source is private, Factrove is not available, and the command may change.
Where this breaks down
If your team edits plans by hand, line by line, in PRs, keep Markdown as the source. Diffs of HTML are miserable to review. Keeping the HTML fits artifacts people review, approve and pass along but mostly don't hand-edit: plans, research write-ups, QA reports, dashboards, design comparisons. When an agent can make 60 things in an afternoon, I'd rather keep the rich version and generate the cheap one when it's needed.
The other thing conversion doesn't solve is the next agent finding the plan at all. A converted plan is useless if nobody knows it exists. I wrote about that part in switching from Claude Code to Codex mid-task. In Factrove, the planned answer is an index file in the repo, factrove.md, listing each artifact's ID and a one-line title. That isn't built yet. A plans/ folder with a README listing what's in it gets you most of the way today.
I'm building Factrove: a home for the HTML artifacts your agents make. The planned workflow would give people a page to read and agents Markdown by ID. It's early, it isn't available yet, and the CLI syntax above may change. If this is the problem you're dealing with, follow me on X for rough builds as they work. Read the planned artifact workflow or join the waitlist.