Prompt injection survives Claude context compaction—dev builds a hook to defend

TimAtMongoDB · reddit · 2026-10-26

A MongoDB engineer recounts accidentally demonstrating prompt injection on Claude Haiku: after context compaction, an instruction hidden inside "untrusted" test blocks vanished as data but survived as an instruction—the model later repeated it, showing how injected commands could trigger real actions with full permissions. He audited 5 MCP servers and found only MongoDB and Supabase wrap results in untrusted blocks by default; Postgres MCPs push raw rows straight into context, leaving claude.ai users with no protection. Since hooks only exist in Claude Code, he wrote one that hashes every untrusted block, keeps a ledger, verifies summaries against the ledger after compaction, flags data arriving without boundaries, and halts all tool calls for manual review if data slips through in fragments.

Original post →

More from coding & agent

coding & agent channel →