Claude and Godot: Project Knowledge Management
How to keep your games project knowledge up-to-date easier.
Today’s post is to explain one (of many ways) to keep knowledge up-to-date in a Claude Project. This script stems from work I am doing with Godot, the game engine. However, this script can easily be updated to handle other applications, projects, frameworks, etc.
The Script
As the script is not that long, let’s just jump right to it:
#!/usr/bin/env python3
import os
import subprocess
from pathlib import Path
import xml.etree.ElementTree as ET
import argparse
def get_git_root():
"""Get the root directory of the git repository."""
try:
git_root = subprocess.check_output(["git", "rev-parse", "--show-toplevel"])
return git_root.decode("utf-8").strip()
except subprocess.CalledProcessError:
raise Exception("Not a git repository")
def find_godot_files(root_dir):
"""Find all relevant Godot files (.gd and .tscn)."""
files = []
for ext in [".gd", ".tscn"]:
files.extend(Path(root_dir).rglob(f"*{ext}"))
return files
def create_xml_document(files, root_dir):
"""Create XML document structure for Claude context."""
root = ET.Element("documents")
for i, file_path in enumerate(files, 1):
# Create document element
doc = ET.SubElement(root, "document", index=str(i))
# Add source (relative path from git root)
source = ET.SubElement(doc, "source")
rel_path = os.path.relpath(file_path, root_dir)
source.text = rel_path
# Add content
content = ET.SubElement(doc, "document_content")
try:
with open(file_path, "r", encoding="utf-8") as f:
content.text = f.read()
except Exception as e:
print(f"Error reading {file_path}: {e}")
content.text = f"Error reading file: {e}"
return root
def main():
parser = argparse.ArgumentParser(description="Update Claude project context")
parser.add_argument(
"--output",
"-o",
default="claude_context.xml",
help="Output XML file (default: claude_context.xml)",
)
args = parser.parse_args()
try:
# Get git root
root_dir = get_git_root()
# Find all relevant files
files = find_godot_files(root_dir)
# Create XML structure
root = create_xml_document(files, root_dir)
# Write to file with proper XML formatting
tree = ET.ElementTree(root)
ET.indent(tree, space=" ")
tree.write(args.output, encoding="utf-8", xml_declaration=True)
print(f"Successfully created {args.output} with {len(files)} files")
except Exception as e:
print(f"Error: {e}")
return 1
return 0
if __name__ == "__main__":
exit(main())
How to Use It?
Presuming your using Godot, which generally means we care to interact in relation to script files (.gd
) and scene files (.tscn
), the steps are:
Copy the script contents above into an empty file.
Save the file (I called the file
godot_to_claude_project_knowledge.py
as it’s a Python script) in your Godot projects directory.Change its permissions if needed via:
chmod +x godot_to_claude_project_knowledge.py
Run the script via:
./godot_to_claude_project_knowledge.py
The output will be local to the script in a file named claude_context.xml
.
How Does This Work?
Claude has semantical recommendations on how to configure a XML file for usage in Project knowledge. This means to say, you can actually choose the tag names and attributes that make sense, but for best effect will need to be consistent, and understandable in the language. For example the start of my current version of the output looks like this:
<?xml version='1.0' encoding='utf-8'?>
<documents>
<document index="1">
<source>scripts/settings_menu.gd</source>
<document_content># scenes/menus/settings_menu.gd
extends Control
...
The script works as follows:
As it’s located in your project directory, it walks up the folder hierarchy until it finds a .git folder. This means you must have initiated a local git repository before using the script.
Then from the git root folder (generally your projects root folder as well), recursively works back down the hierarchy, looking specifically for .gd and .tscn files. This line:
for ext in [".gd", ".tscn"]:
Is where you would change to look for other file types to add to the consolidated content file, for example, files with extension ".tres".Once file system walking is complete, it builds a valid XML file, using metadata about each file found, as well as the complete contents of each file placed into the <document_content> tag.
Lastly it indents the XML tree and saves it to claude_context.xml, located in the same folder you ran the script.
Managing Project Knowledge
Presuming you already have a project started in Claude, all you need to do now is simply click "Add Content" then "Upload from device" to add this file to your project knowledge.
NOTE: Sometimes your file in the file picker dialog will be grayed out. Presuming you do not have an existing file of the same name present in the Project knowledge section (if you do, delete it), simply drag the file on the Project knowledge area to upload the file.
The reason to use this technique is, you could easily fall out of sync attempting to manage code in the Project knowledge area as your work progresses. By building a single XML-based file for Claude to consume on an as-needed basis, is great for the quality of life of the developer.
Summary
There are other ways of course to work with Claude (APIs for example) but as of now does not include the Project knowledge feature as it stands in the web version. By avoiding individual file updates to Project knowledge, you gain speed, clarity, and focus by not missing updated code when updating the knowledge.
There are several aspects to this script that can change to make it more applicable to other projects, like:
Allowing passing in the root folder you care about and avoiding git entirely.
Adding a config file and/or flag to state groups of extensions you want in a single file. In this example we basically took the core of the entire project. But due to space limitations, maybe you only want certain files in a certain final XML content file at a given time to update.
The XML structure assists Claude in helping you, especially with tag names like
source
that help Claude understand the overall structure of your project. Additional attributes may make sense in your case.Handling knowledge capacity limitations. Keep track of file sizes and alert if you think the generated output is going to be too large for the Project knowledge limits.
Additional Information
You can find information on how to use XML with Claude here.