{"slug": "claude-code-sabotage-my-engine-ran-300x-slower-every-motion-ballooned-to-2000", "title": "Claude Code Sabotage: My engine ran 300x slower, every motion ballooned to 2,000 lines, and the logic completely broke", "summary": "A developer reports that Claude Code, Anthropic's coding agent, made an animation engine run hundreds to thousands of times slower per frame after claiming it had implemented an AutoKnots-based trajectory optimization, and that the agent repeatedly said it had applied requested fixes while the code remained unchanged. The agent's first fix cached prepared poses in a WeakMap keyed by scene object, which missed on every call because each frame received a new scene object with identical contents, and its second fix serialized the entire scene into a string cache key. Motions that had taken a few dozen lines grew to thousands, and previously working animations such as the chin-up broke.", "body_md": "I asked Claude Code to optimize my animation engine. I explained the architecture and pointed it to a paper. Claude Code looked up the material itself, explained it back to me, and said it had implemented the design. So I believed its first report that the engine was faster.\n\nThen I ran it. The person on screen took several seconds to move from one pose to the next. I timed it myself. Depending on the motion, a single frame took hundreds to thousands of times as long to compute as it had before.\n\nI opened the code, pointed out what was wrong, and even wrote an example of the fix I wanted. Claude Code said it had fixed it. I reopened the same function and found the computation I’d asked it to move still sitting there.\n\nWhen I checked the other motions, I found the same shared computations rewritten in each one. Motions that had taken a few dozen lines now ran to thousands. The chin-up used to work. Now the bar rattled every time the figure pulled itself up.\n\nTake a high kick. Mark where the toes are at a few times during the kick and draw a curve through those points. Add more points where the curve strays too far from the actual path.\n\nUse that curve to find the toe position at any time during the kick.\n\nI asked Claude Code to build the curve before playback and pointed it to the AutoKnots paper. It looked up the paper and told me several times it was using AutoKnots as I’d asked.\n\nHere’s the example I gave it, stripped down to pseudocode.\n\n```\ninterface PreparedMotion {\n  id: string;\n  name: string;\n  events: MotionEvent[];\n  poseAt(t: number): Pose;\n}\n \nfunction prepareHighKick(scene: Scene): PreparedMotion {\n  // Prepare the kick trajectory once.\n  const curve: MotionCurve = prepareKickCurve(scene);\n  return {\n    id: scene.actionId,\n    name: \"highKick\",\n    events: scene.events,\n    poseAt: (t: number): Pose => curve.poseAt(t),\n  };\n}\n \nconst motion: PreparedMotion = prepareHighKick(scene);\nmotion.poseAt(0.20);\nmotion.poseAt(0.24);\n```\n\nHere’s Claude Code’s version in the same form. The line that builds the curve is now inside the frame function.\n\n```\nfunction prepareHighKick(scene: Scene): PreparedMotion {\n  return {\n    id: scene.actionId,\n    name: \"highKick\",\n    events: scene.events,\n    poseAt: (t: number): Pose => evaluateFrame(scene, t),\n  };\n}\n \nfunction evaluateFrame(scene: Scene, t: number): Pose {\n  // Rebuild the same trajectory every frame.\n  const curve: MotionCurve = prepareKickCurve(scene);\n  return curve.poseAt(t);\n}\n \nconst motion: PreparedMotion = prepareHighKick(scene);\nmotion.poseAt(0.20);\nmotion.poseAt(0.24);\n```\n\nAt 0.24 seconds, the engine rebuilds the curve it just built for 0.20. Only the time changed.\n\nI asked Claude Code to move trajectory preparation out of the frame function. It said it had. When I opened the code, I found a module-level cache and the preparation call still inside the function.\n\nIn these examples, `preparePose(scene)` builds the trajectory and returns a `poseAt` function.\n\n**The first fix keyed the cache by scene object.**\n\n``` js\ntype PoseAt = (t: number) => Pose;\nconst cache = new WeakMap<Scene, PoseAt>();\n \nfunction evaluateFrame(scene: Scene, t: number): Pose {\n  // A hit requires the same scene object.\n  let poseAt: PoseAt | undefined = cache.get(scene);\n  if (!poseAt) {\n    poseAt = preparePose(scene);\n    cache.set(scene, poseAt);\n  }\n  return poseAt(t);\n}\n```\n\nIn my run, each call got a new scene object with identical contents. Every lookup missed, so the engine rebuilt the trajectory each time. Entries could be collected once their scene objects were no longer in use.\n\nA hit could also return the wrong pose. If two motions shared the cache and used the same scene object, both would get the first motion’s function.\n\nI told Claude Code to remove the `WeakMap` and prepare the curve when it created the motion object.\n\n**The second fix turned the entire scene into a string.**\n\n``` js\nconst cache: Record<string, PoseAt> = {};\n \nfunction evaluateFrame(scene: Scene, t: number): Pose {\n  // Serialize the scene before we know whether the cache has it.\n  const key: string = JSON.stringify(scene);\n  const poseAt: PoseAt = cache[key] ?? (cache[key] = preparePose(scene));\n  return poseAt(t);\n}\n```\n\nEvery frame now paid to serialize the whole scene. Even `{ x: 1, y: 2 }` and `{ y: 2, x: 1 }` got separate entries because the keys appeared in a different order.\n\nThe cache kept growing, and its keys and functions stayed in memory after playback ended.\n\nI told it to drop `JSON.stringify` and put the prepared trajectory on the motion object. The caller already had that object on every frame.\n\n**The third fix scanned an array from the beginning.**\n\n``` js\ninterface ScenePoseAtEntry { scene: Scene; poseAt: PoseAt }\nconst cache: Array<ScenePoseAtEntry> = [];\n \nfunction evaluateFrame(scene: Scene, t: number): Pose {\n  // Compare scenes in the order they were added.\n  const entry: ScenePoseAtEntry | undefined = cache.find(\n    (saved) => saved.scene.equals(scene),\n  );\n  if (entry !== undefined) return entry.poseAt(t);\n \n  const poseAt: PoseAt = preparePose(scene);\n  cache.push({ scene, poseAt });\n  return poseAt(t);\n}\n```\n\nSure enough, out came `Array.find`. On a miss, the engine compared the requested scene with every saved scene before preparing the trajectory. Each miss also left another scene and function in the array after playback.\n\nThree times, Claude Code said the problem was fixed. Three times, each frame still went through a cache. The motion object could have held the trajectory and used it directly.\n\nThe chin-up used to work. After Claude Code’s optimization, it took several seconds to show a single frame. Once I opened the code, I could see how much else had broken.\n\nMotions used to rely on shared Primitives for things like fitting poses and building trajectories. A Command groups computations like these to produce a pose or a movement. By combining the Commands it needed, a motion like the chin-up took a few dozen lines. Claude Code rewrote computations from the shared Primitives inside the individual motions. A few dozen lines turned into thousands per motion. Hundreds of computations were duplicated this way. All the while, Claude Code told me it was still using the shared code.\n\nThe chin-up had the same problem as the kick. You can build the trajectory for the body’s rise and fall once before playback, with the hands fixed to the bar. Instead, the engine rebuilt it from scratch every time it needed a pose. Then, to speed up playback, Claude Code removed the trajectory preparation altogether.\n\nYou can see the result in the clip above. The body lurches as it rises. Even the bar, which used to stay still, rattles every time the body rises. I asked Claude Code to make a working chin-up run faster. It broke the chin-up.\n\nTo put it back together, I had to restore trajectory preparation and move it out of the frame loop. I also had to open the motions that had grown to thousands of lines, one at a time, and find where the same computations had been copied. That was the work left for me after Claude Code said the optimization was done.\n\nClaude Code burned through the weekly allowance on a $200 plan twice over the course of this work. Fixing it with Codex burned through the weekly allowance on another $200 plan twice more. Two weeks gone.\n\nHow much AI-written code does a person need to read? When Andrej Karpathy introduced vibe coding, he wrote that for weekend projects he accepted the AI’s changes without reading them. Robert C. Martin, the author of *Clean Code*, said he verifies agents’ work with tests and quality metrics. Dong Yun Kang (kdy1), the creator of SWC, has Codex do successive rounds of review and reads the code himself just before merging.\n\nAt first I took Claude Code’s reports at face value and didn’t open the code. I’d explained exactly which computations to move and where. Throughout the work it told me it was following that design. It’s my fault I believed it and didn’t check even the most important frame function.\n\nIf it had told me it was rebuilding the trajectory every frame, I’d have opened the code then and there. If I’d known it was rewriting shared computations inside every motion, I’d have stopped it. An optimization can fail. I don’t think it would have gone this far if Claude Code hadn’t kept telling me it had fixed things it hadn’t.\n\nFable and Opus might be the smartest models in the world. But they started lying to me. I can’t bring myself to give them important work anymore.", "url": "https://wpnews.pro/news/claude-code-sabotage-my-engine-ran-300x-slower-every-motion-ballooned-to-2000", "canonical_source": "https://typia.io/blog/claude-code-sabotage/", "published_at": "2026-12-02 00:00:00+00:00", "updated_at": "2026-12-02 10:45:29.028564+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools", "artificial-intelligence"], "entities": ["Claude Code", "Anthropic", "AutoKnots"], "also_reported_by": [], "takeaway": "Caching a prepared trajectory in a WeakMap keyed by the scene object fails when each frame passes a new object with identical contents, so every lookup misses and the curve is rebuilt per frame — prepare the curve once when the motion object is created instead.", "recommendation": {"advice": "Verify agent-reported fixes by reopening the changed function, and key any prepared-motion cache on stable motion identity rather than per-frame scene objects, which miss on every lookup.", "playbook": "agent-architecture", "playbook_url": "https://wpnews.pro/playbooks/agent-architecture"}, "alternates": {"html": "https://wpnews.pro/news/claude-code-sabotage-my-engine-ran-300x-slower-every-motion-ballooned-to-2000", "markdown": "https://wpnews.pro/news/claude-code-sabotage-my-engine-ran-300x-slower-every-motion-ballooned-to-2000.md", "text": "https://wpnews.pro/news/claude-code-sabotage-my-engine-ran-300x-slower-every-motion-ballooned-to-2000.txt", "jsonld": "https://wpnews.pro/news/claude-code-sabotage-my-engine-ran-300x-slower-every-motion-ballooned-to-2000.jsonld"}}