PostHog engineer rewrites the SQL parser in Rust with parallel long-running Claude Code sessions: 16K lines, zero divergences in shadow mode, 454x faster on production queries
PostHog transpiles customer SQL to ClickHouse SQL, and its parser was generated by ANTLR (C++). Robbie Coomber rewrote it as a hand-rolled recursive-descent parser in Rust using multiple long-running Claude Code sessions in parallel, two competing approaches sharing one regression suite. The existing C++ parser served as the oracle: property-based testing with Hypothesis (an SQL generator code-generated from the ANTLR grammar, later coverage-guided), anonymized production queries, ShrinkRay reduction and a background agent told to think hard about edge cases fed failing cases to Claude, which was told to load the grammar and C++ source before each fix. The result was 16K lines of parser code, 5K lines of tooling and more tests. In shadow mode it matched millions of parses with zero divergences, and production traffic was switched over after a couple of hours with a 0.1% reverse shadow. The author says none of the code was written by hand; it was all written by Claude Opus 4.7 in May 2026.
The numbers (as reported)
| Code | 16K lines of parser code, 5K lines of tooling, a few more K of tests |
|---|---|
| Speed-up | ~70x on a laptop benchmark; on average 454x faster on production queries |
| Shadow-mode divergences | Zero across millions of parses (~50K production-log queries tested earlier) |
| Time | A couple of days (vs an estimated months without AI) |
Facts
- Company / subject
- PostHog
- Tools
- Claude Code
- Models
- Claude Opus 4.7
- Codebase
- brownfield
- Work type
- Language port
- Stack
- Rust, C++, ANTLR, ClickHouse, Hypothesis
- Published
- 2026-06-24
- Last checked
- 2026-11-20
What the source claims Practitioner (own blog/paper)
Claimed by the builder, writing about their own work. Not checked independently.
- On average 454x faster than the previous parser on production queries 454x (production); ~70x (laptop benchmark)
“On production queries, it was on average 454x faster than the previous parser.”
- Zero divergences from the old parser across millions of parses in shadow mode zero divergences
“I was able to test millions of parses quickly and there were zero divergences.”
- Something that would have taken months was built in a couple of days
“build something that would have taken months for someone with specific knowledge in a couple of days”
Caveats
Written by the PostHog engineer who did the work, on PostHog's blog. The new parser differs from the old one for a tiny subset of contrived queries. 'A couple of days' and 'months' are the author's rough figures, so no duration is typed. The 70x figure is a laptop benchmark; 454x is the production average, where most queries are longer and miss the parser cache. No cost figure given.
More stories by tool: Claude Code
Related topics: Language portsBrownfield codebases