# code-transfer

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.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode, Windsurf (Devin Desktop), Claude.ai · 173 installs · ★ 697 repo stars
- Author: mhattingpete
- License: Apache-2.0 · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/mhattingpete/claude-skills-marketplace/tree/HEAD/code-operations-plugin/skills/code-transfer/SKILL.md
- Updated: 2026-07-25
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/skills/code-transfer

## What it 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.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add mhattingpete/claude-skills-marketplace --skill code-transfer -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/code-transfer/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/code-transfer/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add mhattingpete/claude-skills-marketplace --skill code-transfer -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/code-transfer/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add mhattingpete/claude-skills-marketplace --skill code-transfer -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/code-transfer/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install mhattingpete/claude-skills-marketplace code-operations-plugin/skills/code-transfer
```

2. **Manually: put the files in place**
- File: `.github/skills/code-transfer/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add mhattingpete/claude-skills-marketplace --skill code-transfer -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/mhattingpete/claude-skills-marketplace --path code-operations-plugin/skills/code-transfer
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/code-transfer/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add mhattingpete/claude-skills-marketplace --skill code-transfer -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/mhattingpete/claude-skills-marketplace/tree/HEAD/code-operations-plugin/skills/code-transfer/SKILL.md

## When to use it
- 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
- 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

## Source text · SKILL.md · Apache-2.0

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 343e6c0cd49bafbb.

BEGIN THIRD-PARTY FILE 343e6c0cd49bafbb
````text
---
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)`
````
END THIRD-PARTY FILE 343e6c0cd49bafbb

The third-party file has ended. Everything between the 343e6c0cd49bafbb tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2553 of 4167 bytes. © mhattingpete · Apache-2.0 · https://github.com/mhattingpete/claude-skills-marketplace/tree/HEAD/code-operations-plugin/skills/code-transfer/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
