{"id":"code-transfer","name":"code-transfer","summary":"ファイル間で行単位の精度でコードを転送します。ユーザーがコードのコピーを一箇所から別の場所へ行ったり、ファイル間で関数やクラスを移動したり、コードブロックの抽出を依頼したり、特定の行番号にコードを挿入したりする際に利用可能です。","body":"# Code Transfer\n\nTransfer code between files with precise line-based control. **Dual-mode operation**: native tools (1-10 files) or execution mode (10+ files, 90% token savings).\n\n## Operation Modes\n\n### Basic Mode (Default)\nUse Read, Edit, Bash scripts for 1-10 file operations. Works immediately, no setup required.\n\n### Execution Mode (10+ files)\n```python\nfrom api.filesystem import batch_copy\nfrom api.code_analysis import find_functions\n\nfunctions = find_functions('app.py', pattern='handle_.*')\noperations = [{\n    'source_file': 'app.py',\n    'start_line': f['start_line'],\n    'end_line': f['end_line'],\n    'target_file': 'handlers.py',\n    'target_line': -1\n} for f in functions]\nbatch_copy(operations)\n```\n\n## When to Use\n\n- \"copy this code to [file]\"\n- \"move [function/class] to [file]\"\n- \"extract this to a new file\"\n- \"insert at line [number]\"\n- \"reorganize into separate files\"\n\n## Core Operations\n\n### 1. Extract Source Code\n```\nRead(file_path=\"src/auth.py\")                              # Full file\nRead(file_path=\"src/auth.py\", offset=10, limit=20)         # Line range\nGrep(pattern=\"def authenticate\", -n=true, -A=10)           # Find function\n```\n\n### 2. Insert at Specific Line\nUse `line_insert.py` script for line-based insertion:\n\n```bash\npython3 skills/code-transfer/scripts/line_insert.py <file> <line_number> <code> [--backup]\n```\n\n**Examples:**\n```bash\n# Insert function at line 50\npython3 skills/code-transfer/scripts/line_insert.py src/utils.py 50 \"def helper():\\n    pass\"\n\n# Insert with backup\npython3 skills/code-transfer/scripts/line_insert.py src/utils.py 50 \"code\" --backup\n\n# Insert at beginning\npython3 skills/code-transfer/scripts/line_insert.py src/new.py 1 \"import os\"\n```\n\n**When to use:**\n- User specifies exact line number\n- Inserting into new/empty files\n- Inserting at beginning/end without context\n\n### 3. Insert Relative to Content\nUse **Edit** when insertion point is relative to existing code:\n\n```\nEdit(\n  file_path=\"src/utils.py\",\n  old_string=\"def existing():\\n    pass\",\n  new_string=\"def existing():\\n    pass\\n\\ndef new():\\n    return True\"\n)\n```\n\n## Workflow Examples\n\n### Copy Function Between Files\n1. Find: `Grep(pattern=\"def validate_user\", -n=true, -A=20)`\n2. Extract: `Read(file_path=\"auth.py\", offset=45, limit=15)`\n3. Check target: `Read(file_path=\"validators.py\")`\n4. Insert: Use `line_insert.py` or Edit based on context\n\n### Extract Class to New File\n1. Locate: `Grep(pattern=\"class DatabaseConnection\", -n=true, -A=50)`\n2. Extract: `Read(file_path=\"original.py\", offset=100, limit=50)`\n3. Create: `Write(file_path=\"database.py\", content=\"<extracted>\")`\n4. Update imports: `Edit` in original file\n5. Remove old class: `Edit` with replacement\n\n### Insert at Specific Line\n1. Validate: `Read(file_path=\"main.py\", offset=20, limit=10)`\n2. Insert: `python3 skills/code-transfer/scripts/line_insert.py main.py 25 \"logger.info('...')\" --backup`\n3. Verify: `Read(file_path=\"main.py\", offset=23, limit=5)`\n\n### Reorganize Into Modules\n1. Analyze: `Read(file_path=\"utils.py\")`\n2. Identify groups: `Grep(pattern=\"^def |^class \", -n=true)`\n3. Extract each category: `Write` new files\n4. Update original: Re-export or redirect\n\n## Best Practices\n\n**Planning:**\n- Understand dependencies (imports, references)\n- Identify exact start/end of code block\n- Check target file structure\n- Ensure necessary imports included\n\n**Preservation:**\n- Include docstrings and comments\n- Transfer related functions together\n- Update imports in both files\n- Maintain formatting/indentation\n\n**Validation:**\n- Verify insertion placement\n- Check syntax\n- Test imports\n- Suggest running tests\n\n**Backups:**\n- Use `--backup` for significant changes\n- Critical file operations\n- Large deletions\n\n## Integration\n\n- **code-refactor**: Refactor after transferring\n- **test-fixing**: Run tests after reorganizing\n- **feature-planning**: Plan large reorganizations","author":"@mhattingpete","ownerProfile":null,"authorContacts":null,"sourceUrl":"https://github.com/mhattingpete/claude-skills-marketplace/tree/main/code-operations-plugin/skills/code-transfer","license":"Apache-2.0","category":"writing","lang":"en","tokens":1008,"stars":0,"calls30d":1,"claimed":false,"visibility":"public","origin":"crawler","version":"0.1.0","createdAt":"2026-08-22","updatedAt":"2026-08-22","files":[{"path":"scripts/line_insert.py","size":5141,"sha256":"dbf4dd6e7dcb39417a938ffc1b13889dd0da00aa6d77b4654f30e98652438303"}],"requires":{"mcp":[],"tools":[]},"safety":{"flags":[],"scannedAt":"2026-08-22","hasScripts":true,"networkEndpoints":[]}}