Python SDK Development & Complete Claude Code Migration Guide
The previous 14 parts covered Google Antigravity (AGY) as a daily CLI tool and a team customization platform. This closing installment tackles two practical engineering questions: first, how to use the official Python SDK when agy -p in shell scripts falls short and you need to embed an Agent directly inside a Python service or automated evaluation suite; second, how to migrate an existing setup of MCP servers, Skills, Subagents, and rules from Claude Code, Cursor, Codex, or Gemini CLI in one pass—with clean, zero-residue rollback at any time.
Every detail below has been verified directly against the official sdk.md reference and the built-in migrate-agent-settings Skill. Let’s get straight into the working patterns and edge cases that actually bite in practice.
1. When to Use the Python SDK Instead of agy -p
Part 2 covered headless mode via agy -p --output-format stream-json. For adding an automated review step in GitHub Actions or wiring text transformations into a shell pipeline, the CLI is plenty—there is no need to pull in a Python dependency.
Once you cross into the scenarios below, however, switching to the google-antigravity Python SDK pays off immediately:
| Dimension | agy -p --output-format stream-json |
google-antigravity Python SDK |
|---|---|---|
| Typical use cases | Shell pipelines, single CI steps, quick scripts | Embedded Python services, automated test & eval harnesses |
| Event consumption | Manually parsing JSONL streams from stdout | Native async iteration over text tokens, thoughts, and typed tool_calls |
| Policies & permissions | Global config, repository config, and CLI flags | Declared directly in code via LocalAgentConfig and CapabilitiesConfig |
| Interactive reuse | Single-turn headless calls or --resume continuations |
Spin up a custom terminal assistant in two lines with run_interactive_loop |
The rule of thumb is simple: use agy -p for external orchestration, and reach for the Python SDK whenever you need tight integration with existing Python application code, pytest assertions, or async logging pipelines.

2. Inside the google-antigravity Python SDK
2.1 Installation: Always Use the PyPI Wheel, Never Copy Raw Source
The official SDK lives on GitHub at google-antigravity/antigravity-sdk-python, and installation is a single command:
1 | pip install google-antigravity |
Hard requirement: Do not copy .py files straight from the source repository into your project as a shortcut. The SDK relies on a compiled runtime binary that is only bundled inside the platform-specific wheel published to PyPI. Always install via pip install google-antigravity to pull the matching runtime binary.
2.2 Core Classes and Read-Only-by-Default Safety
The SDK surface is deliberately minimal, built around three classes: Agent, LocalAgentConfig, and CapabilitiesConfig.
Agent(config)is an async context manager invoked viaasync with Agent(config) as agent:. It owns runtime binary discovery, tool wiring, Hook registration, and default policy loading, cleaning up automatically on exit.LocalAgentConfig(system_instructions=..., capabilities=...)defines system instructions and capability boundaries. It runs read-only by default: omitcapabilitiesand the model can only read; passcapabilities=CapabilitiesConfig()explicitly to unlock write and execution tools such asedit_fileandrun_command.
Here is a minimal read-write example covering initialization and response token streaming:
1 | import asyncio |
2.3 Three Async Streams & a CI Audit Script
The response handle returned by await agent.chat(...) exposes three concurrent async streams—a clean fit for production observability and test assertions:
- Response token stream:
async for token in response:yields the final answer incrementally. - Reasoning stream:
async for thought in response.thoughts:streams model reasoning deltas in real time, letting you route them to eval logs or debug panels without polluting user-facing output. - Typed tool-call stream:
async for call in response.tool_calls:yields strongly typed tool-call events with direct access tocall.nameandcall.args.
Below is a complete template ready to drop into a CI audit job or evaluation harness. It intentionally omits capabilities to keep the Agent locked in read-only mode, consumes all three streams concurrently with asyncio.gather, persists the trace, and asserts that no write tool was ever called:
1 | import asyncio |
2.4 Launching a Custom Interactive CLI in Two Lines
If you are building an internal CLI assistant for your team—with baked-in system instructions and capability boundaries—rather than a headless batch job, skip hand-rolling an input() loop and reuse the SDK’s built-in run_interactive_loop:
1 | import asyncio |
Running this script gives you a ready-to-use multi-turn terminal session without maintaining conversation state in your own application code.

3. Frictionless Migration from Claude Code, Cursor, Codex, and Gemini CLI
Many experienced developers hesitate to try AGY because they have already invested months into MCP servers, slash commands, subagents, and rules across Claude Code or Cursor—rebuilding everything from scratch is tedious, and nobody wants a migration script mutating their existing tool setup.
3.1 The Official Strategy: Four-Step Reversible Single-Plugin Migration
AGY ships with a built-in migrate-agent-settings Skill. Trigger it right in chat by asking it to migrate your local Claude Code, Cursor, or Codex settings into Antigravity. Its design follows one strict principle: bundle every migrated asset into a single isolated plugin directory (default recommendation: ~/.gemini/config/plugins/migrated-settings/) without ever modifying a single file belonging to your existing tools.
The workflow enforces four sequential phases:
- Discover (read-only inventory): Scans configuration paths across all four ecosystems and diffs them against MCP servers, Skills, plugins, and active rules already loaded under
~/.gemini/config/(for example, automatically skipping~/.gemini/GEMINI.mdif it is already active so instructions are never injected twice). - Confirm (review the plan): Summarizes item counts and names grouped by source, lists what will be skipped, and never prints plaintext tokens or API keys in chat. Nothing is written to disk until you explicitly approve. If it detects workspace-scoped
.mcp.jsonor.cursor/rules/files, it flags upfront that placing them into a global plugin will make them active across all workspaces, letting you decide whether to include them. - Write (generate a single plugin): Outputs
plugin.json(keeping only the four valid fields:name,displayName,version,description),mcp_config.json,skills/,agents/, andrules/. - Hand back (validate and deliver): Re-reads
plugin.jsonandmcp_config.jsonto confirm valid JSON, then returns the plugin page linkcustomization://migrated-settings.
The biggest win here is complete reversibility: to run an A/B comparison or roll back cleanly, simply toggle the plugin off on the plugin page or delete ~/.gemini/config/plugins/migrated-settings/. Your environment returns to a clean slate in one second, and your original Claude Code or Cursor setup stays completely untouched.
flowchart TD
A["Step 1: Read-Only Discovery<br/>Claude Code / Codex / Cursor / Gemini CLI"] --> B{"Step 2: Route by Asset Type"}
B -->|"MCP / Skills / Commands<br/>Subagents / Rules"| C["Step 3: Write Reversible Single Plugin<br/>~/.gemini/config/plugins/migrated-settings/"]
B -->|"Claude plugins/<br/>Gemini extensions/"| D["Use Native Import Commands<br/>agy plugin import claude / gemini"]
B -->|"Hooks / Permissions<br/>Cursor DB Rules / Legacy SSE"| E["Handle Manually Under New Contract<br/>Rewrite Rules or Bridge via mcp-remote"]
C --> F["Step 4: Validate JSON Syntax<br/>Deliver customization://migrated-settings"]
F --> G{"Any MCP variables Declared?"}
G -->|"Yes: Plugin Disabled by Default"| H["Fill Variables on Plugin Page & Enable"]
G -->|"No: Auto-Loaded"| I["Active on the Next Turn"]
3.2 Four-Ecosystem Configuration Path Map
If you prefer to audit or migrate manually, the table below lists every source path scanned by migrate-agent-settings:
| Source Tool | MCP Config Paths | Skills / Commands / Subagents | Rules / Instruction Files |
|---|---|---|---|
| Claude Code | ~/.claude.json (top-level mcpServers); <workspace>/.mcp.json |
~/.claude/skills/*/SKILL.md; ~/.claude/commands/*.md; ~/.claude/agents/*.md |
~/.claude/CLAUDE.md |
| Codex | [mcp_servers.<name>] in ~/.codex/config.toml |
~/.codex/skills/*/SKILL.md; ~/.codex/prompts/*.md |
~/.codex/AGENTS.md |
| Cursor | ~/.cursor/mcp.json; <workspace>/.cursor/mcp.json |
— | <workspace>/.cursor/rules/*.mdc |
| Gemini CLI | mcpServers in ~/.gemini/settings.json |
~/.gemini/commands/**/*.toml |
~/.gemini/GEMINI.md |
3.3 Five Conversion Rules That Trip Up Most Migrations
Whether you rely on the migration Skill or convert files by hand, these five contract differences determine whether your migrated setup actually runs on the first try:
1. Claude Code Subagent Tool Remapping & Required Frontmatter
When moving ~/.claude/agents/*.md into agents/<name>.md, the Markdown body stays intact as the system prompt, but the YAML frontmatter needs four explicit adjustments:
- Declare the role explicitly: Add
subagent: trueandmainAgent: falseso it is never registered as a top-level main agent. - Declare tools explicitly: Omitting
toolsin AGY grants only a minimal read-only default set. If the original Claude agent omittedtools(meaning full access), populate it explicitly as[read_file, edit_file, write_file, run_command, manage_task, search_web]. - Remap tool names: Map
Read,Glob, andGreptoread_file;EditandMultiEdittoedit_file;Writetowrite_file;Bashtorun_commandandmanage_task;WebSearchandWebFetchtosearch_web. Drop any permission with no AGY equivalent and record the omission. - Strip proprietary fields and avoid name collisions: Remove
modelandcolor. If the agent name collides with a built-in or existing agent (self,browser,research,deepagent,review-agent), prefix it with its source—for example,claude-reviewer.
2. Converting Slash Commands & Prompts to Skills (and the Missing-Frontmatter Trap)
~/.claude/commands/*.md,~/.codex/prompts/*.md, and Gemini CLI’s~/.gemini/commands/**/*.tomlall convert intoskills/<name>/SKILL.md. For nested Gemini CLI paths, join segments with-(e.g.,git/commit.tomlbecomesgit-commit), using the command body (or the TOMLpromptfield) as the Skill content.- Replace argument placeholders like
$ARGUMENTS,$1, and{{args}}with natural-language instructions (for example, “apply the steps above to the user’s current request”). - Common pitfall: Claude Code tolerates a
SKILL.mdwithout frontmatter or without anamefield, whereas AGY silently drops such files. Every migratedSKILL.mdmust include valid YAML frontmatter wherenamematches its parent directory name verbatim anddescriptionis non-empty. Copy siblingscripts/andreferences/directories over as-is.
3. Cursor .mdc to AGY Rules: Trigger Precedence & Glob Formatting
When converting <workspace>/.cursor/rules/*.mdc into standalone rules/<name>.md files, map triggers using this exact precedence order:
alwaysApply: true→trigger: always_on- Non-empty
globs→trigger: glob - Non-empty
description→trigger: model_decision - Both empty →
trigger: manual
Handle two hard constraints upfront: AGY expects globs to be a single comma-separated string matched against absolute paths and filenames. Flatten YAML lists, expand brace expressions like **/*.{ts,tsx} into **/*.ts, **/*.tsx, and prepend **/ to relative paths (src/**/*.ts → **/src/**/*.ts). Individual rule files are also capped at 24 KB—do not silently truncate oversized rules; split them into path-scoped rules and strip legacy tool-specific wording such as “use the Bash tool”.
4. MCP Environment Variables & the Counterintuitive variables Behavior
This is the single most common source of broken MCP servers after migration: mcp_config.json inside an AGY plugin does not automatically expand OS environment variables.
- Only
command,args,env,cwd,url,headers,disabled, andvariablesare recognized (type,timeout,trust, andalwaysAlloware ignored; Gemini CLI’shttpUrland Codex’surlboth map tourl; Codex’shttp_headersmaps toheaders, whileenv_http_headersandbearer_token_env_varconvert into${X}entries insideheaderspaired with avariablesdeclaration). - Delete pass-through env entries: If a stdio server’s
envblock contains"GITHUB_TOKEN": "${GITHUB_TOKEN}","GITHUB_TOKEN": "$GITHUB_TOKEN", or Cursor’s"${env:GITHUB_TOKEN}", remove that line during migration. Without it, the child process automatically inherits the matching OS environment variable; leaving it in without declaringvariablespasses the literal string${GITHUB_TOKEN}instead. - Declare
variablesfor real interpolation: For placeholders that actually need substitution—such as"Authorization": "Bearer ${API_KEY}"on a remote MCP server—normalize$X,${env:X}, and${X:-default}to${X}(documenting defaults indescription), and add avariablesarray (name,title,description) on that server. Note one critical quirk: whenever any server in a plugin declaresvariables, the plugin starts disabled by default—you must fill in the values on the plugin page and enable it manually. - Expand every path to an absolute path upfront:
cwddoes not support variable substitution, and relative paths resolve against the plugin directory itself. Expand${workspaceFolder},$HOME,~, relative paths, and${CLAUDE_PLUGIN_ROOT}to concrete absolute paths before writing. If a server name conflicts with an existing AGY entry, add a source prefix (such asclaude-github).
5. Four Asset Categories That Should Not Be Auto-Migrated
Do not try to force-convert the four categories below with scripts—route them directly to the right path instead:
| Non-Auto-Migrated Asset | Why | Recommended Approach |
|---|---|---|
hooks and permissions in Claude Code settings.json |
Different tool names (Bash/Edit) and protojson/rule syntax |
Rewrite manually following Part 7 (Hooks) and Part 14 (Permissions Engine) |
~/.claude/plugins/ and ~/.gemini/extensions/ |
Complete plugin/extension bundles rather than loose user configs | Run agy plugin import claude or agy plugin import gemini directly |
| Personal user rules in Cursor’s internal client database | Stored in the app’s local DB rather than filesystem config files | Copy the rule text from Cursor’s settings UI into ~/.gemini/config/rules/ |
Legacy SSE MCP servers ("type": "sse" or /sse) |
AGY remote MCP targets Streamable HTTP | Point to the /mcp endpoint if available, or bridge via stdio using npx -y mcp-remote <url> |
4. A Minimal Loop You Can Ship Today
That wraps up all 15 parts of the field guide. You do not need to adopt every feature on day one—pick the smallest closed loop that fixes your highest-friction bottleneck right now:
- Switching your personal daily driver: Run
migrate-agent-settingsonce to pull your existing MCP servers and Skills into the reversiblemigrated-settingsplugin, set up~/.gemini/config/AGENTS.mdalongside/planand your preferred keybindings, and start shipping the same day. - Standardizing a team repository: Commit a concise root
AGENTS.md, split path-scoped.agents/rules/*.mdfiles (staying under 24 KB each), and lock down sensitive files and destructive commands withhooks.jsonand permissiondenyrules so every teammate gets the baseline ongit pull. - Engineering automation & evaluations: Wire simple CI checks with
agy -p --output-format stream-jsonfirst. Once you need to embed an Agent inside a Python test suite, capture reasoning streams, and assert strictly againsttool_calls, switch to thegoogle-antigravityPython SDK—starting from default read-only mode and openingCapabilitiesConfigonly when required.
Series Navigation
- Index: Google Antigravity (AGY) Field Guide · Series Index
- Previous: Permissions Engine, OS Terminal Sandbox & Enterprise Policy Governance
- Further Reading: Google Antigravity (AGY) Engineering in Practice · Series Index — real-world setups for directory-scoped session isolation, lazy-loading MCP proxies, dual-protocol Hooks, and one-click cross-machine backups.





















