Claude's API is stateless. It remembers nothing between calls; your code sends the whole conversation every time. On your laptop, the history was an array in memory. On Workers, that breaks.
A Worker can run in many places at once, and one copy serves many people. An array at the top of the file would be shared between users, and it would vanish whenever Cloudflare recycles the copy. Cloudflare's own best-practice list flags module-level request state as a bug for exactly this reason.
Memory needs a home that is one per user, stays put, and keeps its data. That's a Durable Object: an instance with a name, its own SQLite database, and the guarantee that a given name always reaches the same instance. Cloudflare's Agents SDK wraps one in an Agent class with this.sql built in.