I play Dungeons and Dragons. Specifically, I run it: I’m the Dungeon Master, which means I’m responsible for the world, the story, the NPCs, the rules, the pacing, and the improvised dialogue. It’s a lot of overhead, and prep time is always limited.

I’ve been using AI heavily for prep: developing characters, writing descriptions, planning encounters. But during live sessions, keeping the AI contextually aware of the game state while running the session is difficult. I was either neglecting the AI or breaking the flow of the game to type updates.

The solution was to connect them directly.

The Setup: Virtual Tabletops

Fantasy Grounds Unity (FGU) is a leading Virtual Tabletop (VTT) that replicates the tabletop experience online. It has a rich extension system and a large library of licensed content. We play online, keeping a Discord open for voice chat while the game’s mechanics and narrative play out in the FGU chat window.

FGU Has No Native AI Integration

To use AI during a session, you normally have to manually copy chat logs or summarize events in a separate browser window, then copy responses back. That workflow falls apart at a live table. I needed the AI to watch the session alongside me, building its own awareness of events, so I could query it with minimal friction.

The Architecture

The bridge consists of three components:

  1. A Lua extension inside FGU: This registers custom GM slash commands. When typed, the extension writes a JSON request directly to FGU’s console log.
  2. A Python server running locally: This monitors FGU’s chatlog.html for new entries, parsing them in real time to accumulate session history in memory. When a GM command is written to the console log, the Python server packages the history, the command, and the campaign notes, and sends them to the Anthropic API.
  3. The Anthropic API (Claude): Receives the full context, generates the response, and returns it to the Python server, which automatically copies it to the system clipboard for the GM to paste.
FGU chatlog.html  →  Python monitors continuously
                      Session events accumulate in memory (no API call, no cost)

GM types /npctalk  →  console.log  →  Python detects it
                       Full context sent to Anthropic API
                       Response copied to clipboard
                       GM: Ctrl+V into FGU chat → Enter

How the Live Context Works

FGU writes everything—dialogue, attack rolls, damage, turn markers—to chatlog.html. The Python server polls this file every 0.4 seconds. New lines are parsed, stripped of HTML, and appended to an in-memory list. Mechanical events (like dice rolls) are prefixed with [ROLL] so Claude understands they are game mechanics rather than narrative text.

Every few seconds, pending events are flushed into the conversation history as a [TABLE] message. Claude is instructed via the system prompt to absorb these silently without generating a response.

When a slash command is sent, the entire conversation history is dispatched to the API. Claude has seen the full context of the session and can respond instantly in character.

The Campaign Notes

Two markdown files provide Claude’s background knowledge:

These are loaded at server startup and injected into the system prompt of every API call.

The GM Commands

All commands are slash commands typed in the FGU chat box:

Cost & Performance

API calls are only made when a GM command is sent; monitoring the logs is free. A full session typically costs less than a dollar using Claude Haiku, depending on the size of the note files and query frequency.

The full project, including the Lua extension and Python server templates, is available on GitHub (heyjudeuk/fgu-claude-bridge).

Note for developers: FGU Unity 5.x uses Comm.registerSlashHandler for slash commands. Older documentations reference ChatManager.registerSlashCommand, which has been deprecated.