Skip to content

Instantly share code, notes, and snippets.

@Strajk
Last active November 17, 2025 20:48
Show Gist options
  • Select an option

  • Save Strajk/32ddd8ca23841abcccb647c083c6c84d to your computer and use it in GitHub Desktop.

Select an option

Save Strajk/32ddd8ca23841abcccb647c083c6c84d to your computer and use it in GitHub Desktop.
Fetch an agent definition from a URL and run claude with it
#!/usr/bin/env python3
# /// script
# dependencies = []
# ///
"""
Fetch an agent definition from a URL and run claude with it.
"""
import sys
import json
import re
import subprocess
def parse_frontmatter(content):
"""Parse YAML frontmatter from markdown content."""
# Match content between --- markers
match = re.match(r"^---\s*\n(.*?)\n---\s*\n(.*)", content, re.DOTALL)
if not match:
raise ValueError("No frontmatter found in content")
frontmatter_text = match.group(1)
body = match.group(2)
# Simple YAML parser for our use case
metadata = {}
for line in frontmatter_text.split("\n"):
line = line.strip()
if ":" in line:
key, value = line.split(":", 1)
metadata[key.strip()] = value.strip()
return metadata, body
def fetch_url(url):
# Use curl to avoid SSL cert issues
result = subprocess.run(
["curl", "-fsSL", url], capture_output=True, text=True, check=True
)
return result.stdout
def build_agent_json(metadata, body):
"""Build the agent JSON structure."""
name = metadata.get("name", "agent")
description = metadata.get("description", "")
agent_config = {name: {"description": description, "prompt": body.strip()}}
return json.dumps(agent_config)
def main():
if len(sys.argv) < 2:
print("Usage: claude-agent <url>", file=sys.stderr)
print("\nExample:", file=sys.stderr)
print(
" claude-agent https://raw.githubusercontent.com/foo.md",
file=sys.stderr,
)
sys.exit(1)
url = sys.argv[1]
# Fetch and parse the agent definition
print(f"Fetching agent from: {url}", file=sys.stderr)
content = fetch_url(url)
metadata, body = parse_frontmatter(content)
agent_name = metadata.get("name", "agent")
print(f"Loaded agent: {agent_name}", file=sys.stderr)
print(f"Description: {metadata.get('description', 'N/A')}", file=sys.stderr)
# Build the agent JSON
agent_json = build_agent_json(metadata, body)
# Construct the claude command
cmd = [
"claude",
# TODO: Replace with more nuanced approach
"--dangerously-skip-permissions",
"--agents",
agent_json,
"--append-system-prompt",
f"Use the {agent_name} agent to handle the task.",
]
print("", file=sys.stderr)
subprocess.run(cmd, check=True)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment