Duncan Leung

Duncan Leung

๐Ÿ“š Learning, ๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป Building, ๐Ÿ“ Documenting...

Hi! I'm Duncan Leung and I currently lead Frontend Engineering at Airvet.

In a previous career I worked overseas in Beijing as a Product Manager at a skunkworks studio building digital experience projects for Ford Motor (China) and consulted on UX projects for Starwood Hotels. During this time I also mentored startups at Chinaccelerator and ran startup events and hackathons in Shanghai.

๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป I'm a self taught software developer, and this is a place for me to jot down some notes. I mostly cover Javascript, Typescript, React, and software development.

Latest Writing

01

Why We Built a Compaction System Instead of Handing Off to New Agents

aiclaude-codeopenrigmulti-agent

When a long-running orchestrator hits context limits, the obvious move is to hand off to a fresh agent. We tried that. The startup overhead, lost momentum, and broken continuity made it worse than the problem it solved โ€” for our use case. So we built a compaction system instead: one that writes ground truth to disk, restores from it, and distills session knowledge into a wiki page via an API call to Haiku. Recent research shows neither approach is categorically better โ€” compaction drops behavioral constraints, handoff carries a 'handoff tax' โ€” but for same-model orchestrators that accumulate judgment over time, compaction with external ground truth wins. Here's how the system works and what the literature says.

02

Surviving the Dumb Zone: A Checkpoint System for Claude Code's /compact

aiclaude-codeopenrig

Claude Code's /compact command compresses your conversation to free context, but it silently drops external state mutations, abandoned approaches, and behavioral constraints. I built a precompact/postcompact checkpoint system that writes ground truth to disk before compaction and cross-checks it afterward โ€” including live reconciliation against git, CI, and external systems. Here's the design, the research behind it, the failure modes it prevents, and how OpenRig's native compaction system eventually superseded these custom skills.

03

Building an Observer That Turns Claude Code Sessions into a Knowledge Base

aiclaude-codeknowledge-management

Every Claude Code session produces decisions, patterns, and context that vanish when the terminal closes. I built a daemon that watches for session endings, extracts the knowledge, distills it with Haiku, and compiles it into an Obsidian wiki with Sonnet โ€” turning every coding session into searchable institutional memory for about $20/month.

04

Claude Code Research Tools: A Decision Guide

aiclaude-code

Claude Code has a dozen ways to research a question โ€” from a single MCP call to a 98-agent adversarial pipeline. This guide maps every research tool by cost, agent count, and use case so you pick the right one the first time. Includes the full source of a custom deep-research-plus workflow that adds a Perplexity search lane to Claude Code's built-in deep-research pipeline.

05

The Attention Mechanism: Context Rot and the Lost-in-the-Middle Problem

ai

LLM context rot isn't a bug. It's a mathematical property of how the attention mechanism works. Three interacting failure modes (softmax's sum-to-one constraint, RoPE's distance decay, and causal masking's primacy bias) combine to produce the U-shaped attention curve where models attend well to the beginning and end of context but lose the middle. Understanding the mechanism changes how you structure prompts and manage context.

Newsletter

Stay updated, receive the latest post straight to your mailbox