r/ClaudeWorkflows • • Oct 19 '26

Selected Workflow [Workflow] Claude Code Autonomous Agent for Baldur's Gate 3: A Deep Dive into MCP, Memory, and Long-Running Task Automation

Claude Code Autonomous Agent for Baldur's Gate 3: A Deep Dive into MCP, Memory, and Long-Running Task Automation

Workflow value: 98/100
Status: active · Freshness: 70/100 · Confidence: 1.00 · Level: expert
Categories: Quality Control, Token Saving, Context & Memory, Debugging, MCP, Multi-Agent
Original source: r/ClaudeCode post/comment

What problem this solves

Automating complex, long-running, and stateful tasks in a dynamic 3D environment using an AI agent, specifically demonstrated by having Claude Code autonomously play Baldur's Gate 3. It addresses challenges in memory management, crash recovery, and custom tool integration for such tasks.

Summary

An advanced workflow demonstrating how to set up Claude Code with a custom Multi-Agent Communication Protocol (MCP) server, game mods, and robust memory management (including Git-based versioning and a 'keeper pass' for distillation) to autonomously play a complex video game like Baldur's Gate 3. It highlights techniques for handling long-running sessions, context management, and learning from experience.

Why it is useful

This workflow is exceptionally valuable because it pushes the boundaries of what's possible with AI agents, demonstrating a highly sophisticated and robust system for autonomous interaction with a complex, dynamic environment. It provides concrete patterns for advanced memory management (Git-based versioning, HANDOFF.md, lessons.md, keeper pass), custom tool integration via MCP, and handling long-running, stateful tasks. The detailed technical description, specific examples, and links to code and a blog post make it an excellent resource for advanced users looking to build similar complex agentic systems. It moves beyond simple coding tasks to full-fledged autonomous operation, offering a blueprint for future AI applications.

Workflow

  1. Set up Claude Code (claude -p) with all built-in tools turned off.

  2. Develop a custom MCP server in Python to provide specialized tools for game interaction.

  3. Develop a Lua mod for the target game (Baldur's Gate 3) to report perception and execute actions via the MCP server.

  4. Implement a Vulkan layer for capturing screenshots and an SDL shim for sending input (clicks) to the game.

  5. Create a runner script to launch the game, start each AI session, and recover from crashes.

  6. Manage memory per session: start each session with a briefing including character sheet, playthrough summary, and the last session's HANDOFF.md.

  7. Restrict Claude's memory access to its own memory folder, managed exclusively through MCP tools.

  8. Implement an end_session tool that lints the session's memory, commits it to a Git repository, and ensures HANDOFF.md is present.

  9. Between sessions, run a 'keeper pass' (using the same model at low effort) to fold the session log into curated files and distill rules into a lessons.md file.

  10. Distill learned rules into lessons.md using a WHEN situation: what happened → what to do format.

Tools / artifacts

  • Claude Code (claude -p)

  • Custom Python MCP server

  • Lua game mod (for Baldur's Gate 3)

  • Vulkan layer (for screenshots)

  • SDL shim (for clicks)

  • Game runner script

  • HANDOFF.md

  • Memory folder (managed by MCP tools)

  • Git repository (for memory versioning)

  • Curated notes files

  • lessons.md (with distilled rules)

  • Baldur's Gate 3 game

Validation signals

  • Opus 5.5 successfully 'killed the Netherbrain on its 12th try and the ending rolled' without human intervention.

  • Detailed statistics provided: 20,809 tool calls, 862 screenshots, 2.2 billion cached input tokens.

  • Specific example of problem-solving: successfully completed the 'Faith-Leap trial' after fixing a tool leak, taking 36 minutes, 674 tool calls, and multiple reloads.

  • Nautiloid opening scenario runs 9 of 9 times at approximately $1.50 per run.

  • GitHub repository with code provided.

  • Accompanying blog post with further details.

Limitations

  • High complexity and significant setup cost (time and financial investment).

  • Requires advanced programming skills (Python, Lua, potentially Vulkan/SDL knowledge) for implementation.

  • Specific game integration components (Lua mod, Vulkan layer) are not directly reusable for other games or applications.

  • The 'keeper pass' is mentioned but its specific prompt or detailed logic for distillation is not fully elaborated.

Rate this workflow

Upvote this post if the workflow is useful, reproducible, or worth recommending.

Downvote if it is vague, outdated, unsafe, overhyped, or not reproducible.

Reply if it worked for you, failed, is outdated, or has a better alternative.


This post was generated automatically from the workflow library database.

4 Upvotes

0 comments sorted by