PostHog's AI-powered installation wizard has been quietly burning through tokens at $6.67 per run, prompting engineer Vincent G. to investigate what the company playfully calls "token embezzlement." His deep dive revealed three critical inefficiencies that inflated costs by as much as 150% between the most and least expensive wizard runs.
The wizard, which helps thousands of organizations onboard onto PostHog by understanding business logic and configuring products automatically, appeared to work smoothly on the surface. But the underlying token consumption told a different story.
The Investigation
Vincent's first lead pointed to the dashboard creation step, which consumed roughly $1.47 for relatively simple operations. His initial hypothesis centered on excessive context size, but clearing the context backfired, actually increasing costs due to cache write overhead. Attempting to use subagents as a workaround proved equally problematic, as they failed to share cache and often hung without terminating.
The breakthrough came from analyzing the variance in wizard runs. The 150% cost difference between the most and least efficient runs suggested runaway tool calls were the primary culprit. This led Vincent to identify three specific problems:
Wizard bureaucracy caused unnecessary file re-reads. The agent would repeatedly access files it had already processed, wasting tokens on redundant operations.
Compaction amnesia triggered additional re-reads. The system's memory management inadvertently discarded context that should have been retained, forcing the wizard to fetch the same information multiple times.
Fly-away subagents spawned processes that hung indefinitely without returning results. These orphaned agents consumed resources while contributing nothing to the actual onboarding workflow.
The Fix
With the root causes identified, PostHog implemented several targeted optimizations. The team improved caching mechanisms to prevent amnesia-induced re-reads, reduced bureaucratic overhead in file access patterns, banned unreliable subagents entirely, and standardized deterministic flows to ensure consistent, predictable execution paths.
These changes directly address the token consumption issues without compromising the wizard's core functionality. The improvements come as PostHog continues expanding its product suite, recently adding 39 new features across analytics, session replay, and experimentation tools.
Why This Matters
For companies building AI-powered features, this case study highlights the hidden costs that can accumulate in production systems. Token consumption rarely appears as a line item during development but can significantly impact unit economics at scale. PostHog's transparent approach to debugging and optimizing these costs offers a practical blueprint for other teams facing similar challenges.
The open-source analytics platform's willingness to share both the problem and solution publicly reflects its broader commitment to helping builders understand the full operational picture of running AI agents in production. As AI tooling becomes standard infrastructure for small businesses and startups, understanding these cost dynamics becomes increasingly critical for sustainable growth.
Sources
1 checkedHow we cover tool news: Create With's tool desk drafts these reports with AI from the sources listed above and checks them against those sources before publishing.




