#!/usr/bin/env python3 """ Patch ~/.claude.json to add the cwd field to the state-hub MCP entry. claude mcp add-json silently drops the cwd field. Run this script after any claude mcp add-json call to restore it. Usage: python3 scripts/patch_mcp_cwd.py """ import json import os from pathlib import Path CLAUDE_JSON = Path.home() / ".claude.json" STATE_HUB_DIR = Path(__file__).resolve().parent.parent # state-hub/ def main() -> None: if not CLAUDE_JSON.exists(): print(f"ERROR: {CLAUDE_JSON} not found. Run 'claude mcp add-json' first.") raise SystemExit(1) config = json.loads(CLAUDE_JSON.read_text()) servers = config.setdefault("mcpServers", {}) if "state-hub" not in servers: print("ERROR: 'state-hub' not found in ~/.claude.json. Run 'claude mcp add-json' first.") raise SystemExit(1) entry = servers["state-hub"] cwd_str = str(STATE_HUB_DIR) if entry.get("cwd") == cwd_str: print(f"OK: cwd already set to {cwd_str}") return entry["cwd"] = cwd_str CLAUDE_JSON.write_text(json.dumps(config, indent=2) + "\n") print(f"Patched: ~/.claude.json state-hub.cwd = {cwd_str}") if __name__ == "__main__": main()