Skip to main content
skill CX Codex

code-transfer — Claude Code skill: move code between files by line

A skill for precise code transfer between files using line-based positioning. Useful when you need to move a function to another file, extract a class into a separate module, or insert code at a specific line number.

Apache-2.0 173 installs ★ 697 updated 2026-07-25

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add mhattingpete/claude-skills-marketplace --skill code-transfer -a claude-code
Open on GitHub

What code-transfer does

The skill offers two operation modes. The default mode uses native tools and works for 1–10 files without extra setup. For larger operations (10+ files), execution mode relies on Python scripts from api.filesystem and api.code_analysis, saving 90% of tokens.

Core operations: locate source code via Read with a line range or Grep, insert by line number using line_insert.py or the built-in Edit when the insertion point depends on existing content. When moving code blocks, remember to transfer imports and validate syntax. The skill includes ready-made patterns: copying a function, extracting a class to a new file, inserting at a specific line, and splitting a file into modules. Significant changes can use the --backup option.

What it helps with

  • move a function or class to another file
  • extract a code block into a separate module
  • insert code at an exact line without surrounding context
  • copy code between files while preserving imports
  • reorganize code across multiple files

Example prompts for the agent

  • Copy the validate_user function from auth.py to validators.py
  • Move the DatabaseConnection class into a new database.py file and update imports
  • Insert logger.info('starting') at line 25 in main.py with a backup

How to install code-transfer

1Skills CLI (Vercel)

npx skills add mhattingpete/claude-skills-marketplace --skill code-transfer -a claude-code

2Manually: put the files in place

~/.claude/skills/code-transfer/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/code-transfer/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about code-transfer

How do I install code-transfer in Claude Code?

Run npx skills add mhattingpete/claude-skills-marketplace --skill code-transfer -a claude-code in your terminal, then edit ~/.claude/skills/code-transfer/SKILL.md.

What does code-transfer do?

It moves code between files with line-level precision. Extract a function, move a class to another module, insert code at a specific line number, or reorganize code across separate files.

When should I use execution mode instead of the default mode?

Use execution mode for operations spanning 10 or more files to save tokens. It requires Python to be available. For smaller transfers (under 10 files), the native tool mode works immediately.

Source text

SKILL.md · Apache-2.0
---
name: code-transfer
description: Transfer code between files with line-based precision. Use when users request copying code from one location to another, moving functions or classes between files, extracting code blocks, or inserting code at specific line numbers.
---

# Code Transfer

Transfer code between files with precise line-based control. **Dual-mode operation**: native tools (1-10 files) or execution mode (10+ files, 90% token savings).

## Operation Modes

### Basic Mode (Default)
Use Read, Edit, Bash scripts for 1-10 file operations. Works immediately, no setup required.

### Execution Mode (10+ files)
```python
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
} for f in functions]
batch_copy(operations)
```

## When to Use

- "copy this code to [file]"
- "move [function/class] to [file]"
- "extract this to a new file"
- "insert at line [number]"
- "reorganize into separate files"

## Core Operations

### 1. Extract Source Code
```
Read(file_path="src/auth.py")                              # Full file
Read(file_path="src/auth.py", offset=10, limit=20)         # Line range
Grep(pattern="def authenticate", -n=true, -A=10)           # Find function
```

### 2. Insert at Specific Line
Use `line_insert.py` script for line-based insertion:

```bash
python3 skills/code-transfer/scripts/line_insert.py <file> <line_number> <code> [--backup]
```

**Examples:**
```bash
# Insert function at line 50
python3 skills/code-transfer/scripts/line_insert.py src/utils.py 50 "def helper():\n    pass"

# Insert with backup
python3 skills/code-transfer/scripts/line_insert.py src/utils.py 50 "code" --backup

# Insert at beginning
python3 skills/code-transfer/scripts/line_insert.py src/new.py 1 "import os"
```

**When to use:**
- User specifies exact line number
- Inserting into new/empty files
- Inserting at beginning/end without context

### 3. Insert Relative to Content
Use **Edit** when insertion point is relative to existing code:

```
Edit(
  file_path="src/utils.py",
  old_string="def existing():\n    pass",
  new_string="def existing():\n    pass\n\ndef new():\n    return True"
)
```

## Workflow Examples

### Copy Function Between Files
1. Find: `Grep(pattern="def validate_user", -n=true, -A=20)`
2. Extract: `Read(file_path="auth.py", offset=45, limit=15)`
3. Check target: `Read(file_path="validators.py")`
4. Insert: Use `line_insert.py` or Edit based on context

### Extract Class to New File
1. Locate: `Grep(pattern="class DatabaseConnection", -n=true, -A=50)`
2. Extract: `Read(file_path="original.py", offset=100, limit=50)`
3. Create: `Write(file_path="database.py", content="<extracted>")`
4. Update imports: `Edit` in original file
5. Remove old class: `Edit` with replacement

### Insert at Specific Line
1. Validate: `Read(file_path="main.py", offset=20, limit=10)`
2. Insert: `python3 skills/code-transfer/scripts/line_insert.py main.py 25 "logger.info('...')" --backup`
3. Verify: `Read(file_path="main.py", offset=23, limit=5)`

### Reorganize Into Modules
1. Analyze: `Read(file_path="utils.py")`
2. Identify groups: `Grep(pattern="^def |^class ", -n=true)`
3. Extract each category: `Write` new files
4. Update original: Re-export or redirect

## Best Practices

**Planning:**
- Understand dependencies (imports, references)
- Identify exact start/end of code block
- Check target file structure
- Ensure necessary imports included

**Preservation:**
- Include docstrings and comments
- Transfer related functions together
- Update imports in both files
- Maintain formatting/indentation

**Validation:**
- Verify insertion placement
- Check syntax
- Test imports
- Suggest running tests

**Backups:**
- Use `--backup` for significant changes
- Critical file operations
- Large deletions

## Integration

- **code-refactor**: Refactor after transferring
- **test-fixing**: Run tests after reorganizing
- **feature-planning**: Plan large reorganizations

© mhattingpete · Apache-2.0 · mhattingpete/claude-skills-marketplace

Similar skills

All skills for Agent setup: memory, context, orchestration →

From the same set15

The whole set →
timeline-creator timeline-creator turns a project's tasks and dates into an interactive HTML timeline with Gantt bars, phases and milestones. Handy when a plan has to live in one file. CX Codex +1 337installs code-refactor code-refactor is a Claude Code skill for bulk code changes across files: renaming variables and functions, replacing deprecated patterns, and updating API calls. It automatically selects a mode that saves up to 90% of tokens for 10+ files. CX Codex +1 304installs feature-planning The feature-planning skill turns feature requests and complex changes into ordered implementation plans with concrete tasks. Use it before coding when the scope needs structure. CX Codex +1 297installs code-execution The code-execution skill runs Python locally for bulk file work, code analysis, transformations, and Git tasks. It fits large or multi-step workflows. CX Codex +1 294installs conversation-analyzer conversation-analyzer analyzes your local Claude Code session logs to detect recurring errors, repetitive prompts, and workflow bottlenecks. CX Codex +1 249installs technical-doc-creator technical-doc-creator builds HTML documentation for APIs and systems with code samples, architecture diagrams, syntax highlighting, and workflow steps. CX Codex +1 221installs ensemble-solving ensemble-solving spawns three parallel subagents to explore diverse solutions, scores each approach against weighted criteria, and returns the best outcome with trade-offs. CX Codex +1 218installs project-bootstrapper project-bootstrapper — a skill for Claude Code, Cursor, Codex and other platforms that scaffolds a new project or levels up an existing one: directories, linter configs, tests, Git hooks, CI/CD and documentation. CX Codex +1 212installs

Project sponsors

Companies that keep this analytics open