AI Coding Tool Context Migration: Backup and Validation Steps

    Learn how to back up and migrate global instructions, project rules, and long-term memory between AI coding tools. This guide covers preparation, a Python rule-conversion script, sensitive-data cleanup, and validation checks while accounting for differences in configuration formats and import support.

    Introduction: Protecting Context When Account Access Is at Risk

    A major AI coding tool recently experienced a wave of account suspensions, leaving many developers unable to access their accounts. The provider has not fully explained the reasons, and community discussions remain largely speculative.

    This guide does not examine account enforcement mechanisms or discuss ways to evade detection. Instead, it focuses on protecting the custom instructions, project rules, and long-term memory developers have accumulated when account access is disrupted.

    1. Three Types of Context Assets and Their Format Differences

    Developers typically accumulate three types of context assets when using AI coding tools.

    Asset type Common storage location Common format Migration challenge
    Global instructions User-level configuration directory Plain text or Markdown Configuration fields and variable syntax may differ in the destination tool
    Project rules Rule files in the code repository Text files with tool-specific extensions Required paths and syntax vary between tools
    Long-term memory The tool’s local data directory JSON or database files Structures are highly customized, and the destination tool may not support direct imports

    Storage locations and formats differ across tools. All paths, filenames, and field names in this guide are examples. Before proceeding, consult the official documentation for both tools and confirm the file locations on your machine.

    2. Prepare Before Migrating

    1. Record tool versions. Note the versions of the source and destination tools, then review the destination tool’s configuration and import documentation.

    2. Locate your assets. Use commands such as ls -la and find to list files in the configuration directory. Record the path and size of each asset.

    3. Create a complete backup. Copy the entire configuration directory to a dated backup directory and generate a hash manifest. Replace the example paths below with your actual paths:

      1. SRC=~/.config/example-tool
      2. BAK=~/backup/example-tool-$(date +%Y%m%d)
      3. cp -a "$SRC" "$BAK"
      4. find "$BAK" -type f -exec sha256sum {} + > "$BAK.manifest.txt"

      macOS does not include sha256sum by default. Use shasum -a 256 instead.

    4. Remove sensitive information. Check instruction and rule files for API keys, access tokens, and internal service addresses. Remove these details or replace them with placeholders before migration.

    5. Prepare a test project. Choose a repository where you can validate the migration without affecting production work.

    3. Migration Steps

    Step 1: Extract Global Instructions

    Copy the global instruction file to a temporary directory and confirm that it uses UTF-8 encoding.

    Check for variables or syntax specific to the source tool, then adapt them according to the destination tool’s documentation. If the destination tool has no corresponding configuration field, save the instructions as a document in the project root for team reference.

    Step 2: Convert Project Rules

    The following script demonstrates how to convert a hypothetical rule format into Markdown. It assumes that each rule begins with a ## Title line, followed by its body text.

    Check the actual source format and modify parse_old_format if necessary.

    The script requires Python 3.9 or later and has no third-party dependencies.

    1. import argparse
    2. import sys
    3. from pathlib import Path
    4. def parse_old_format(text: str) -> list[dict]:
    5. """Example parser: each rule starts with '## Title', followed by its body."""
    6. rules = []
    7. current = None
    8. for line_no, line in enumerate(text.splitlines(), start=1):
    9. if line.startswith("## "):
    10. if current is not None:
    11. rules.append(current)
    12. current = {"title": line[3:].strip(), "content": []}
    13. elif current is not None:
    14. current["content"].append(line)
    15. elif line.strip():
    16. raise ValueError(
    17. f"Line {line_no} appears before the first rule: {line!r}"
    18. )
    19. if current is not None:
    20. rules.append(current)
    21. return [
    22. {"title": r["title"], "content": "\n".join(r["content"]).strip()}
    23. for r in rules
    24. ]
    25. def convert_rules(src: Path, dst: Path) -> int:
    26. if not src.is_file():
    27. raise FileNotFoundError(f"Source file does not exist: {src}")
    28. if dst.exists():
    29. raise FileExistsError(
    30. f"Destination file already exists; choose another path "
    31. f"or back it up first: {dst}"
    32. )
    33. # Encoding errors raise UnicodeDecodeError, a subclass of ValueError.
    34. text = src.read_text(encoding="utf-8")
    35. rules = parse_old_format(text)
    36. if not rules:
    37. raise ValueError("No rules were parsed; check the source file format")
    38. blocks = [f"### {r['title']}\n\n{r['content']}" for r in rules]
    39. dst.parent.mkdir(parents=True, exist_ok=True)
    40. dst.write_text("\n\n".join(blocks) + "\n", encoding="utf-8")
    41. return len(rules)
    42. def main() -> int:
    43. parser = argparse.ArgumentParser(description="Convert a project rules file")
    44. parser.add_argument("src", type=Path, help="Path to the source rules file")
    45. parser.add_argument(
    46. "dst",
    47. type=Path,
    48. help="Output file path (existing files will not be overwritten)",
    49. )
    50. args = parser.parse_args()
    51. try:
    52. count = convert_rules(args.src, args.dst)
    53. except (OSError, ValueError) as exc:
    54. print(f"Conversion failed: {exc}", file=sys.stderr)
    55. return 1
    56. print(f"Converted {count} rules -> {args.dst}")
    57. return 0
    58. if __name__ == "__main__":
    59. raise SystemExit(main())

    Example input (old/rules.txt):

    1. ## Do Not Add New Dependencies
    2. Do not add third-party libraries without review.

    Example output (new/project-rules.md):

    1. ### Do Not Add New Dependencies
    2. Do not add third-party libraries without review.

    Run the script:

    1. python convert_rules.py old/rules.txt new/project-rules.md

    Use the output path and filename required by the destination tool. The script refuses to overwrite existing files, helping prevent accidental loss of content in the destination directory.

    Step 3: Handle Long-Term Memory

    Long-term memory is the most difficult asset to migrate. Follow this sequence:

    1. Use the source tool’s export feature first, if available. If it has no export feature, you can write a script to parse its JSON files and output Markdown. The script should read only backup copies, not the original directory.
    2. Preserve the timestamp, topic, and source file for each memory entry.
    3. Manually spot-check entries and remove outdated or incorrect information.
    4. If the destination tool provides an official import feature, use it. If no public import interface exists, do not guess at interfaces or directly modify the tool’s internal database. Instead, save the memory entries as project documentation and clearly state that they are reference material, not entries the tool will automatically read as memory.

    Step 4: Validate the Migration

    Check Method Pass criteria
    Backup integrity Compare files in the backup directory against the hash manifest All file hashes match
    Rule count Compare the number of source rule headings with the number of ### headings in the destination file The counts match
    Instruction content Compare global instructions section by section, checking rewritten variables and paths Every section has a corresponding entry, and all changes are recorded
    Memory entries Randomly sample 10 entries —