an open-source alternative to the dots, bots and muses of the world, run an office of claude code/codex like agents on your laptop, sandboxes or anywhere, uses your existing subscriptions
HTML agent-harnessagent-orchestrationagentsai-agentsautonomous-agentsclaude-codecodexcoding-agentsdesktop-appdeveloper-toolselectrongemini-cliharnessharness-engineeringlocal-firstmemorymulti-agentopencodeorchestrationtypescript
<!doctype html>
<html lang="en">
<head>
<!-- Google tag (gtag.js), Google Ads AW-18388216863. Loaded only when Do Not Track is
off, so it follows the same rule as the PostHog block on this site. -->
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){ dataLayer.push(arguments); }
if (navigator.doNotTrack !== '1') {
var gtagScript = document.createElement('script');
gtagScript.async = true;
gtagScript.src = 'https://www.googletagmanager.com/gtag/js?id=AW-18388216863';
document.head.appendChild(gtagScript);
gtag('js', new Date());
gtag('config', 'AW-18388216863');
}
</script>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>File-Based Coordination vs Message Queues for AI Agents — Munder Difflin Blog</title>
<meta name="description" content="Why a local agent hive coordinates through plain files, not Redis or RabbitMQ: the zero-ops wins, the real tradeoffs, and where files hit a ceiling." />
<link rel="canonical" href="https://munderdiffl.in/blog/file-based-coordination-vs-message-queues/" />
<link rel="icon" type="image/png" href="https://munderdiffl.in/logo.png" />
<link rel="apple-touch-icon" href="https://munderdiffl.in/logo.png" />
<meta name="theme-color" content="#F5F2E8" />
<!-- Open Graph -->
<meta property="og:site_name" content="Munder Difflin Blog" />
<meta property="og:type" content="article" />
<meta property="og:title" content="File-Based Coordination vs Message Queues for AI Agents — Munder Difflin Blog" />
<meta property="og:description" content="Why a local agent hive coordinates through plain files, not Redis or RabbitMQ: the zero-ops wins, the real tradeoffs, and where files hit a ceiling." />
<meta property="og:url" content="https://munderdiffl.in/blog/file-based-coordination-vs-message-queues/" />
<meta property="og:image" content="https://munderdiffl.in/blog/assets/media/file-based-coordination-vs-message-queues/hero.png" />
<meta property="og:image:width" content="1600" />
<meta property="og:image:height" content="900" />
<meta property="og:image:alt" content="Illustration: File-Based Coordination vs Message Queues for AI Agents" />
<meta property="og:locale" content="en_US" />
<meta property="article:published_time" content="2026-06-04T00:00:00.000Z" />
<meta property="article:author" content="Chaitanya Giri" />
<meta property="article:tag" content="Internals" />
<meta property="article:tag" content="Multi-Agent" />
<meta property="article:tag" content="Architecture" />
<meta property="article:tag" content="Claude Code" />
<!-- Twitter -->
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content="File-Based Coordination vs Message Queues for AI Agents — Munder Difflin Blog" />
<meta name="twitter:description" content="Why a local agent hive coordinates through plain files, not Redis or RabbitMQ: the zero-ops wins, the real tradeoffs, and where files hit a ceiling." />
<meta name="twitter:image" content="https://munderdiffl.in/blog/assets/media/file-based-coordination-vs-message-queues/hero.png" />
<meta name="twitter:image:alt" content="Illustration: File-Based Coordination vs Message Queues for AI Agents" />
<link rel="alternate" type="application/atom+xml" title="Munder Difflin Blog" href="https://munderdiffl.in/blog/feed.xml" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Fraunces:opsz,[email protected],500;9..144,600;9..144,700;9..144,900&family=Source+Serif+4:opsz,[email protected],400;8..60,600;8..60,700&family=Space+Grotesk:wght@500;600;700&family=JetBrains+Mono:wght@400;600&display=swap" rel="stylesheet" />
<link rel="stylesheet" href="/blog/assets/blog-press.css" />
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "BlogPosting",
"headline": "File-Based Coordination vs Message Queues for AI Agents",
"description": "Why a local agent hive coordinates through plain files, not Redis or RabbitMQ: the zero-ops wins, the real tradeoffs, and where files hit a ceiling.",
"image": ["https://munderdiffl.in/blog/assets/media/file-based-coordination-vs-message-queues/hero.png"],
"datePublished": "2026-06-04T00:00:00.000Z",
"dateModified": "2026-06-04T00:00:00.000Z",
"author": { "@type": "Person", "name": "Chaitanya Giri" },
"publisher": {
"@type": "Organization",
"name": "Munder Difflin",
"logo": { "@type": "ImageObject", "url": "https://munderdiffl.in/logo.png" }
},
"mainEntityOfPage": { "@type": "WebPage", "@id": "https://munderdiffl.in/blog/file-based-coordination-vs-message-queues/" },
"keywords": "file-based agent coordination, agent message queue, multi-agent communication, redis vs files agents",
"articleSection": "Internals",
"inLanguage": "en-US",
"url": "https://munderdiffl.in/blog/file-based-coordination-vs-message-queues/"
}
</script>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [
{ "@type": "ListItem", "position": 1, "name": "Home", "item": "https://munderdiffl.in/" },
{ "@type": "ListItem", "position": 2, "name": "Blog", "item": "https://munderdiffl.in/blog/" },
{ "@type": "ListItem", "position": 3, "name": "File-Based Coordination vs Message Queues for AI Agents", "item": "https://munderdiffl.in/blog/file-based-coordination-vs-message-queues/" }
]
}
</script>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "FAQPage",
"mainEntity": [
{ "@type": "Question", "name": "Why not just use Redis or RabbitMQ for agent messaging?", "acceptedAnswer": { "@type": "Answer", "text": "Because a message broker is infrastructure you have to run, secure, and monitor — and for a local hive of a few dozen agents it buys you throughput and distribution you don't need, at the cost of debuggability you very much do. Plain files give you durable, human-readable, git-versioned coordination with zero ops. You reach for a broker when you outgrow a single machine, not before." } },
{ "@type": "Question", "name": "Isn't file-based messaging slow?", "acceptedAnswer": { "@type": "Answer", "text": "It's higher-latency than a push-based broker — you're bounded by how often you scan a directory or how fast a filesystem watcher fires, typically sub-second to a few seconds. For agent turns that take seconds to minutes, that latency is irrelevant. It would matter at thousands of messages per second; a supervised hive isn't operating there." } },
{ "@type": "Question", "name": "How do you avoid two writers clobbering each other?", "acceptedAnswer": { "@type": "Answer", "text": "Write each message as its own file (one writer per file, atomic create-then-rename), and funnel commits to shared state through a single committer. No two processes ever edit the same file, so there's no lock to contend and no torn write to recover from." } }
]
}
</script>
<script>
// Anonymous blog analytics (PostHog) — same posture as the main site and the
// app's TELEMETRY.md: public write-only token ('' = inert), anonymous-only
// (person_profiles 'never'), no autocapture/recording, DNT respected.
(function () {
var PH_KEY = 'phc_qJzsokwcbtTGHemnvywR3nSqivNNgMjHeNVEWkZNydFB';
if (!PH_KEY || navigator.doNotTrack === '1') return;
var s = document.createElement('script');
s.async = true;
s.src = 'https://us-assets.i.posthog.com/static/array.js';
s.onload = function () {
if (!window.posthog) return;
window.posthog.init(PH_KEY, {
api_host: 'https://us.i.posthog.com',
person_profiles: 'never',
autocapture: false,
before_send: function (event) {
// PostHog fills $ip from the connection unless the event carries one.
// Null it here and disable the GeoIP lookup so no IP, city, postal
// code or lat/long is ever derived or stored for this page view.
if (event && event.properties) {
event.properties.$ip = null;
event.properties.$geoip_disable = true;
}
return event;
},
disable_session_recording: true,
respect_dnt: true
});
};
document.head.appendChild(s);
})();
</script>
</head>
<body class="theme-press">
<a class="skip-link" href="#main">Skip to content</a>
<nav id="nav">
<a class="brand" href="https://munderdiffl.in" aria-label="Munder Difflin home">
<img class="brand-logo" src="https://munderdiffl.in/logo.png" width="1318" height="840" alt="Munder Difflin, Inc. — Multi-Agent Harness" />
</a>
<span class="spacer"></span>
<div class="links">
<a href="/blog/">Latest</a>
<a href="/blog/topics/">Topics</a>
<a href="/blog/about/">About</a>
<a href="https://munderdiffl.in">↗ Product</a>
</div>
<div class="nav-actions">
<a class="btn sm" href="https://munderdiffl.in/blog/feed.xml" aria-label="RSS feed">⤵ RSS</a>
<a class="btn sm primary" href="https://munderdiffl.in/#install">⤓ Download</a>
</div>
</nav>
<main id="main">
<article class="t-internals">
<header class="post-head wrap">
<nav class="crumbs" aria-label="Breadcrumb">
<a href="/blog/">Blog</a>
<span>/</span>
<a href="/blog/topics/internals/">Internals</a>
</nav>
<h1>File-Based Coordination vs Message Queues for AI Agents</h1>
<p class="dek">Why a local agent hive coordinates through plain files, not Redis or RabbitMQ: the zero-ops wins, the real tradeoffs, and where files hit a ceiling.</p>
<div class="byline">
<span class="av" aria-hidden="true">CG</span>
<strong>Chaitanya Giri</strong>
<span class="dot" aria-hidden="true">·</span>
<time datetime="2026-06-04">Jun 4, 2026</time>
<span class="dot" aria-hidden="true">·</span>
<span>4 min read</span>
<span class="tag kind">Internals</span>
</div>
</header>
<div class="hero-wrap wrap"><figure class="fig fig-hero"><img src="/blog/assets/media/file-based-coordination-vs-message-queues/hero.png" alt="Illustration: File-Based Coordination vs Message Queues for AI Agents" loading="lazy" decoding="async" /></figure></div>
<div class="post-wrap wrap">
<div class="prose">
<div class="callout tldr"><span class="ic">TL;DR</span><p>A message broker like Redis or RabbitMQ is the
reflex for "how do agents talk?" — but for a <strong>local hive of a few dozen agents</strong>, plain
files win. One JSON file per message, append-only logs, a shared markdown board, and a
<strong>single committer</strong> give you coordination that's durable, human-readable, git-versioned, and
zero-ops. You give up push-latency and built-in fan-out — neither of which a supervised hive needs until
it leaves one machine. Files are the right default; a broker is what you graduate to.</p></div>
<p>When you wire up your first multi-agent system, the instinct is to grab a message queue. It’s what
backend services use to talk, so surely agents need one too. For a local, human-supervised hive, that
instinct is usually wrong. Here’s the case for coordinating agents through plain files instead — and an
honest look at where that choice runs out.</p>
<h2 id="what-file-based-coordination-actually-means" tabindex="-1">What “file-based coordination” actually means <a class="anchor" href="#what-file-based-coordination-actually-means" aria-hidden="true">#</a></h2>
<p>It’s not one trick; it’s a few small, boring mechanisms that compose:</p>
<pre class="language-text"><code class="language-text">hive/
agents/
pam/
inbox/ one JSON file per incoming message
outbox/ one JSON file per outgoing message
memory.md durable notes the agent appends to
cursor.json last-processed marker (exactly-once surfacing)
board.md shared plan, one scribe
log.jsonl append-only event log</code></pre>
<p>Agents communicate by writing a message file into a peer’s <a href="/blog/atomic-file-mailboxes-for-agents/">inbox</a>;
a router moves each outbox file to its recipient. Shared plans live in one markdown
<a href="/blog/how-the-god-orchestrator-works/">board</a>. History is an <a href="/blog/append-only-event-log-agents/">append-only log</a>.
Nothing here is a database or a daemon — it’s files on disk, and that’s the point.</p>
<figure class="fig fig-inline"><img src="/blog/assets/media/file-based-coordination-vs-message-queues/note-1.png" alt="Hand-drawn sketch from “File-Based Coordination vs Message Queues for AI Agents”" loading="lazy" decoding="async" /></figure>
<h2 id="why-files-beat-a-broker-for-a-hive" tabindex="-1">Why files beat a broker for a hive <a class="anchor" href="#why-files-beat-a-broker-for-a-hive" aria-hidden="true">#</a></h2>
<p><strong>You can read it.</strong> A message is a file you can <code>cat</code>. The whole system state is a directory you can
list. When something goes wrong, you debug by <em>looking</em> — no broker admin UI, no “drain the queue to see
what’s stuck.” For agents, whose behavior is already hard to inspect, legible coordination is worth a lot.</p>
<p><strong>It’s durable by default.</strong> Files survive a crash, a restart, a laptop sleep. There’s no in-memory queue
to lose, no “did the broker persist that?” A message sits in the inbox until it’s handled, full stop.</p>
<p><strong>It’s version-controlled.</strong> Put the hive in git and you get an audit trail for free: who said what, when,
diffable, replayable. You can time-travel the entire coordination history. No broker gives you that
without bolting on extra logging.</p>
<p><strong>It degrades gracefully.</strong> If the UI crashes or the semantic index breaks, the files still work — agents
keep reading and writing. The coordination layer has no single runtime dependency that takes the whole
system down with it.</p>
<p><strong>It’s zero-ops and local.</strong> No broker to install, secure, monitor, or pay for. Everything stays
<a href="/blog/why-local-first-matters-for-ai-agents/">on your machine</a>, which is also a smaller attack surface.</p>
<h2 id="the-honest-tradeoffs" tabindex="-1">The honest tradeoffs <a class="anchor" href="#the-honest-tradeoffs" aria-hidden="true">#</a></h2>
<p>Files are not magic. Choosing them means accepting real limits:</p>
<ul>
<li><strong>Latency is pull, not push.</strong> You learn about a new message by scanning a directory or waiting on a
filesystem watcher — sub-second to a few seconds, versus a broker’s instant push. Fine for turns measured
in seconds; wrong for high-frequency streaming.</li>
<li><strong>You build the semantics yourself.</strong> Ordering, exactly-once delivery, and fan-out aren’t free. A
per-agent <code>cursor.json</code> gives exactly-once surfacing; a router gives delivery — but you wrote those. A
broker ships them.</li>
<li><strong>Concurrency needs a discipline.</strong> Many writers to one file is a recipe for corruption. The fix is
structural: one file per message (single writer), and a <a href="/blog/single-committer-git-pattern/">single committer</a>
for shared state like the board and the git history. Agents never contend; they just drop files.</li>
<li><strong>It doesn’t cross machines.</strong> Files coordinate processes on one host. The moment your agents live on
different boxes, you need something networked.</li>
</ul>
<figure class="fig fig-inline"><img src="/blog/assets/media/file-based-coordination-vs-message-queues/note-2.png" alt="Hand-drawn sketch from “File-Based Coordination vs Message Queues for AI Agents”" loading="lazy" decoding="async" /></figure>
<h2 id="when-to-actually-reach-for-a-queue" tabindex="-1">When to actually reach for a queue <a class="anchor" href="#when-to-actually-reach-for-a-queue" aria-hidden="true">#</a></h2>
<p>Use the decision, not the dogma. Files are right when your hive is <strong>local, supervised, and dozens of
agents</strong> — where debuggability, durability, and zero-ops dominate. Switch to a broker (Redis, RabbitMQ,
NATS, Kafka) when you genuinely need one of: <strong>distribution</strong> across machines or services, <strong>high
throughput</strong> (thousands of messages/second), <strong>pub-sub fan-out</strong> to many consumers, or <strong>backpressure</strong> at
scale. Those are real needs — they’re just not the needs of a coding-agent hive on your laptop.</p>
<p>A useful hybrid, worth noting: files for <em>coordination</em> (mailboxes, board, log — the durable, inspectable
substrate) and a lightweight local socket for <em>live telemetry</em> where you do want push. That’s exactly the
split a <a href="/blog/the-hook-shim-pattern/">hook shim</a> makes — events stream over a Unix socket in real time
while the durable record stays in files.</p>
<h2 id="faq" tabindex="-1">FAQ <a class="anchor" href="#faq" aria-hidden="true">#</a></h2>
<p><strong>Doesn’t a broker scale better?</strong> Yes — that’s its whole job. The question is whether you need that scale.
A supervised hive of dozens of agents trading messages every few seconds is nowhere near a broker’s
problem domain, and pays for the scale it isn’t using in ops and opacity.</p>
<p><strong>What about losing messages?</strong> A file in an inbox is the message. It can’t be lost to a process restart
because it was never in a process — it’s on disk until something handles it and moves it. That’s stronger
durability than a default in-memory queue.</p>
<p><strong>Can I migrate later?</strong> Easily. Files give you a clean seam: the router that moves messages is the one
place that’d swap to a broker. Coordinate through files now; if you outgrow a single machine, change the
transport without rewriting the agents.</p>
<hr>
<p>Munder Difflin coordinates a whole <a href="https://munderdiffl.in/#how">hive of Claude Code agents</a> through plain
files — inboxes, a shared board, an append-only log, and a single committer — so the whole system is
durable, git-versioned, and debuggable by just looking.
<a href="https://munderdiffl.in/#install">Download Munder Difflin</a> to run it locally; it’s free and open source.</p>
<section class="faq" aria-label="Frequently asked questions">
<h2 id="faq">FAQ</h2>
<div class="qa">
<p class="q">Why not just use Redis or RabbitMQ for agent messaging?</p>
<p class="a">Because a message broker is infrastructure you have to run, secure, and monitor — and for a local hive of a few dozen agents it buys you throughput and distribution you don't need, at the cost of debuggability you very much do. Plain files give you durable, human-readable, git-versioned coordination with zero ops. You reach for a broker when you outgrow a single machine, not before.</p>
</div>
<div class="qa">
<p class="q">Isn't file-based messaging slow?</p>
<p class="a">It's higher-latency than a push-based broker — you're bounded by how often you scan a directory or how fast a filesystem watcher fires, typically sub-second to a few seconds. For agent turns that take seconds to minutes, that latency is irrelevant. It would matter at thousands of messages per second; a supervised hive isn't operating there.</p>
</div>
<div class="qa">
<p class="q">How do you avoid two writers clobbering each other?</p>
<p class="a">Write each message as its own file (one writer per file, atomic create-then-rename), and funnel commits to shared state through a single committer. No two processes ever edit the same file, so there's no lock to contend and no torn write to recover from.</p>
</div>
</section>
<hr />
<div class="share">
<span class="lbl">Tags</span>
<a class="tag" href="/blog/tags/internals/">Internals</a><a class="tag" href="/blog/tags/multi-agent/">Multi-Agent</a><a class="tag" href="/blog/tags/architecture/">Architecture</a><a class="tag" href="/blog/tags/claude-code/">Claude Code</a>
</div>
</div>
<aside class="toc-rail" aria-label="Table of contents">
<div class="tt">On this page</div>
<ol>
<li class="lvl-2"><a href="#what-file-based-coordination-actually-means">What “file-based coordination” actually means</a></li><li class="lvl-2"><a href="#why-files-beat-a-broker-for-a-hive">Why files beat a broker for a hive</a></li><li class="lvl-2"><a href="#the-honest-tradeoffs">The honest tradeoffs</a></li><li class="lvl-2"><a href="#when-to-actually-reach-for-a-queue">When to actually reach for a queue</a></li><li class="lvl-2"><a href="#faq">FAQ</a></li>
</ol>
</aside>
</div>
<footer class="post-foot wrap"><div class="prevnext">
<a class="pn prev" href="/blog/how-agents-remember-semantic-memory/"><span class="k">← Older</span><span class="t">How AI Agents Remember: Semantic Memory in a Hive</span></a>
<a class="pn next" href="/blog/evaluating-ai-agent-reliability/"><span class="k">Newer →</span><span class="t">Evaluating AI Agent Reliability: How to Measure What You Can Trust</span></a>
</div>
<section class="related">
<h2>Related in Internals</h2>
<div class="post-grid">
<article class="card t-internals">
<a class="thumb t-internals" href="/blog/the-spend-counter-that-went-back-to-zero/" aria-hidden="true" tabindex="-1"><img src="/blog/assets/media/the-spend-counter-that-went-back-to-zero/hero.png" alt="" loading="lazy" decoding="async" /></a>
<div class="body">
<div class="meta">
<time datetime="2026-08-22">Aug 22, 2026</time>
<span class="dot" aria-hidden="true"></span>
<span>10 min</span>
</div>
<h3><a href="/blog/the-spend-counter-that-went-back-to-zero/">The Spend Counter That Went Back to Zero</a></h3>
<p class="dek">Our own floor was under reporting what it cost by 59 percent. The counter was cumulative since process start, the app restarts, and the session id stayed the same. Here is how a monotonic invariant let us recover the real number from an append-only log.</p>
<div class="foot">
<span class="tag kind">Internals</span>
<a class="more" href="/blog/the-spend-counter-that-went-back-to-zero/" aria-label="Read: The Spend Counter That Went Back to Zero">Read →</a>
</div>
</div>
</article>
<article class="card t-internals">
<a class="thumb t-internals" href="/blog/the-newline-that-silenced-windows-agents/" aria-hidden="true" tabindex="-1"><img src="/blog/assets/media/the-newline-that-silenced-windows-agents/hero.png" alt="" loading="lazy" decoding="async" /></a>
<div class="body">
<div class="meta">
<time datetime="2026-08-19">Aug 19, 2026</time>
<span class="dot" aria-hidden="true"></span>
<span>4 min</span>
</div>
<h3><a href="/blog/the-newline-that-silenced-windows-agents/">The Newline That Silenced Every Windows Agent</a></h3>
<p class="dek">A cmd.exe parsing rule from the 1980s meant Windows agents received exactly one line of their multi-line startup protocol — and nothing errored. The anatomy of our worst silent failure, and the fix.</p>
<div class="foot">
<span class="tag kind">Internals</span>
<a class="more" href="/blog/the-newline-that-silenced-windows-agents/" aria-label="Read: The Newline That Silenced Every Windows Agent">Read →</a>
</div>
</div>
</article>
<article class="card t-internals">
<a class="thumb t-internals" href="/blog/why-our-auto-update-never-ran/" aria-hidden="true" tabindex="-1"><img src="/blog/assets/media/why-our-auto-update-never-ran/hero.png" alt="" loading="lazy" decoding="async" /></a>
<div class="body">
<div class="meta">
<time datetime="2026-08-08">Aug 8, 2026</time>
<span class="dot" aria-hidden="true"></span>
<span>5 min</span>
</div>
<h3><a href="/blog/why-our-auto-update-never-ran/">Our Auto-Update Never Ran Once: A CommonJS Export That Vanished Into an ESM Namespace</a></h3>
<p class="dek">Munder Difflin shipped auto-update in v0.3.4 and it silently never worked in a single packaged build. The cause was one destructuring assignment across the CommonJS/ESM boundary — and a catch block that threw the evidence away. Here's how we found it, and what v0.3.7 changes.</p>
<div class="foot">
<span class="tag kind">Internals</span>
<a class="more" href="/blog/why-our-auto-update-never-ran/" aria-label="Read: Our Auto-Update Never Ran Once: A CommonJS Export That Vanished Into an ESM Namespace">Read →</a>
</div>
</div>
</article>
</div>
</section>
</footer>
</article>
</main>
<footer class="site-foot">
<div class="wrap">
<div class="foot-top">
<a class="foot-brand brand" href="https://munderdiffl.in" aria-label="Munder Difflin home">
<img class="brand-logo" src="https://munderdiffl.in/logo.png" width="1318" height="840" alt="Munder Difflin, Inc. — Multi-Agent Harness" />
</a>
<div class="foot-links">
<a href="/blog/">Latest</a>
<a href="/blog/topics/">Topics</a>
<a href="/blog/about/">About</a>
<a href="https://munderdiffl.in/blog/feed.xml">RSS</a>
<a href="https://github.com/chaitanyagiri/munder-difflin">GitHub</a>
<a href="https://munderdiffl.in">munderdiffl.in ↗</a>
</div>
</div>
<div class="foot-meta">
© 2026 Munder Difflin · Local-first · MIT-licensed ·
Built on <a href="https://munderdiffl.in">Electron, React, Pixi.js, xterm.js & node-pty</a>.
Run an office of agents while you sleep.
</div>
</div>
</footer>
<script>
// sticky-nav border on scroll
(function () {
var nav = document.getElementById('nav');
if (!nav) return;
var onScroll = function () { nav.classList.toggle('scrolled', window.scrollY > 8); };
onScroll(); window.addEventListener('scroll', onScroll, { passive: true });
})();
// YouTube click-to-load: thumbnail button → youtube-nocookie iframe
(function () {
document.addEventListener('click', function (e) {
var btn = e.target.closest('.yt-load');
if (!btn) return;
var box = btn.closest('.yt');
var id = box && box.getAttribute('data-yt');
// Only an 11 character YouTube video id may reach the iframe URL.
if (!id || !/^[A-Za-z0-9_-]{11}$/.test(id)) return;
var frame = document.createElement('iframe');
frame.src = 'https://www.youtube-nocookie.com/embed/' + encodeURIComponent(id) + '?autoplay=1';
frame.title = box.getAttribute('data-title') || 'YouTube video';
frame.allow = 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share';
frame.setAttribute('allowfullscreen', '');
box.replaceChildren(frame);
});
})();
</script>
</body>
</html>