Code Transfer
Transfer code between files with line-based precision. Use when users request copying code from one location to another, moving functions or classes b
What Is Code Transfer?
Code Transfer is a specialized development skill designed to facilitate the precise movement and copying of code between files, offering granular, line-based control. Whether you need to extract specific code blocks, relocate entire functions or classes, or reorganize your codebase into modular components, Code Transfer streamlines the process. It supports both small-scale and large-scale code transfers, making it an indispensable tool for developers who frequently refactor or restructure their code. The skill operates efficiently across single files and can handle bulk operations involving ten or more files with significant token savings.
Why Use Code Transfer?
Modern software projects often require developers to reorganize code for clarity, maintainability, and scalability. Manually moving code between files is time-consuming and error-prone, especially when it involves maintaining exact line numbers and preserving code context. Code Transfer addresses these challenges by providing:
- Precision: Move or copy code blocks, functions, or classes with exact line-based control.
- Efficiency: Automate repetitive file operations and reduce manual intervention.
- Scalability: Efficiently handle code transfers across multiple files, even in large projects.
- Consistency: Maintain code style and integrity during transfers, lowering the risk of human error.
Common scenarios include moving functions to utility modules, extracting classes into separate files, or inserting code at specific lines based on project requirements. By using Code Transfer, teams can accelerate refactoring tasks and focus on higher-level design and implementation.
How to Get Started
Getting started with Code Transfer is straightforward. The skill operates in two primary modes—Basic Mode for small to medium file sets and Execution Mode for large-scale operations.
Basic Mode (Default)
Basic Mode is optimized for operations involving up to ten files. It leverages native tools and requires no additional setup. You can use commands such as Read, Edit, and bash scripts to perform code extraction and insertion tasks.
Example: Extracting and Inserting Code
## Extract lines 10 to 30 from auth.py
Read(file_path="src/auth.py", offset=10, limit=20)
## Insert extracted code into handlers.py at line 50
Edit(file_path="src/handlers.py", insert_at=50, content=extracted_code)Execution Mode (10+ files)
For projects requiring code transfer across more than ten files, Execution Mode provides batch operations with up to 90% token savings. This mode utilizes APIs for efficient bulk transfers.
Example: Moving All Handler Functions
from api.filesystem import batch_copy
from api.code_analysis import find_functions
functions = find_functions('app.py', pattern='handle_.*')
operations = [{
'source_file': 'app.py',
'start_line': f['start_line'],
'end_line': f['end_line'],
'target_file': 'handlers.py',
'target_line': -1 # Append at the end
} for f in functions]
batch_copy(operations)This approach is ideal for large-scale refactoring and reorganizing codebases.
Key Features
- Line-Based Extraction: Read exact line ranges or patterns from source files.
- Targeted Insertion: Insert code at specific line numbers in target files.
- Pattern-Based Selection: Use grep-like queries to find and move functions or classes by name or pattern.
- Batch Operations: Automate code transfer across many files, saving development time.
- Dual-Mode Operation: Seamlessly switch between native and execution modes depending on the project size.
- No Setup Required for Small Projects: Instantly usable for up to ten files without configuration.
Practical Commands
- Extract a full file:
Read(file_path="src/auth.py") - Extract specific lines:
Read(file_path="src/auth.py", offset=10, limit=20) - Find and extract a function using grep:
Grep(pattern="def authenticate", -n=True, -A=10) - Insert at a specific line:
python line_insert.py src/handlers.py 50 extracted_code.py
Best Practices
- Always Verify Line Numbers: Before transferring code, confirm the exact line ranges to avoid partial or incorrect extraction.
- Use Pattern Matching for Functions/Classes: When moving reusable components, leverage pattern-based search to ensure you capture the entire definition.
- Batch Similar Operations: For large refactoring, group similar transfer tasks to maximize efficiency, particularly in Execution Mode.
- Maintain Code Formatting: After insertion, review target files to confirm consistent formatting and indentation.
- Test After Transfers: Run automated tests to ensure functionality remains intact after code movement, especially for logic-critical components.
Important Notes
- Code Transfer is most effective when line numbers and code boundaries are clearly defined.
- For batch operations, ensure that source and target files exist and have appropriate permissions.
- Execution Mode’s batch operations require access to specific APIs and may need environment-specific configuration.
- When inserting code at specific lines, be cautious to avoid overwriting existing code unless intentional.
- Always back up important files before performing large-scale code transfers, especially in production environments.
- The skill is designed for use cases such as copying, moving, extracting, and reorganizing code, not for merging or resolving code conflicts automatically.
- For more information and advanced usage, consult the official repository.
More Skills You Might Like
Explore similar skills to enhance your workflow
Typescript Pro
TypeScript Pro automation, integration, and advanced type-safe development workflows
Deploying Decoy Files for Ransomware Detection
Deploys canary files (honeytokens) across file systems to detect ransomware encryption activity in real time
Stress Test
/em -stress-test — Business Assumption Stress Testing
Slack Message Formatter
A Claude Code skill for slack message formatter workflows and automation
Axiom Xcode MCP
iOS and xOS development guidance for Xcode MCP patterns and best practices
Positioning Workshop
Run a positioning workshop that surfaces target customer, unmet need, category, benefits, and differentiation. Use when your product messaging