Code Extraction & Modification Tools¶
Extraction tools allow AI assistants to surgically extract specific code elements and safely modify them without affecting surrounding code.
Tools in This Category¶
| Tool | Description | Tier |
|---|---|---|
extract_code | Surgically extract functions/classes by name | Community |
update_symbol | Safely replace code with automatic backup | Community |
rename_symbol | Rename across entire codebase | Pro |
extract_code¶
Extract a specific function, class, or method by name.
What It Does¶
extract_code retrieves exactly the code you need by name—no line number guessing:
- Surgical extraction: Get only the specified symbol
- Dependency info: What imports/dependencies the code needs
- Token estimate: How many tokens the extracted code uses
- Cross-file deps: Optionally resolve imports from other files (Pro+)
When AI Agents Use This¶
- Getting a specific function to review or modify
- Reducing token usage (extract vs read entire file)
- Understanding what dependencies code needs
- Preparing code for modification with
update_symbol
Quick Reference¶
| Property | Value |
|---|---|
| Tier | Community |
| Languages | Python, JavaScript, TypeScript, Java, JSX, TSX |
| Token Cost | ~50-500 tokens (much less than reading files) |
Parameters¶
| Parameter | Type | Required | Description |
|---|---|---|---|
file_path | string | ✓* | Path to source file |
code | string | ✓* | Source code string |
target_type | string | ✓ | "function", "class", or "method" |
target_name | string | ✓ | Name of the element to extract |
language | string | Language hint (auto-detected) | |
include_context | bool | Include surrounding context | |
include_cross_file_deps | bool | Resolve cross-file imports (Pro+) |
*Provide either file_path or code, not both.
Example Usage¶
Prompt:
"Get the process_order function from orders.py"
Tool Call:
Prompt:
"Extract the UserService class"
Tool Call:
Response Format¶
{
"data": {
"success": true,
"target_type": "function",
"target_name": "process_order",
"source": "def process_order(order_id: str, items: list) -> Order:\n \"\"\"Process a new order.\"\"\"\n order = Order(order_id)\n for item in items:\n order.add_item(item)\n order.calculate_total()\n return order",
"line_start": 45,
"line_end": 52,
"dependencies": ["Order"],
"imports_needed": ["from models import Order"],
"token_estimate": 87
},
"tier_applied": "community",
"duration_ms": 28
}
Why This Matters¶
| Reading Entire File | Using extract_code |
|---|---|
| ~10,000 tokens for 500-line file | ~100 tokens for one function |
| AI must find the right code | Exact code delivered |
| May hallucinate changes | Verified code exists |
| Context window bloat | Surgical precision |
Tier Differences¶
| Feature | Community | Pro | Enterprise |
|---|---|---|---|
| Single-file extraction | ✅ | ✅ | ✅ |
| Max file size | 1 MB | 10 MB | Unlimited |
| Cross-file dependencies | — | ✅ | ✅ |
| Dependency graph | — | ✅ | ✅ |
| Variable promotion | — | ✅ | ✅ |
| Organization-wide search | — | — | ✅ |
update_symbol¶
Safely replace a function, class, or method with new code.
What It Does¶
update_symbol replaces specific code elements without touching surrounding code:
- Automatic backup: Creates backup before modifying
- Syntax validation: Verifies new code is valid
- Surrounding preservation: Doesn't affect other code
- Precise targeting: By name, not line numbers
When AI Agents Use This¶
- Fixing bugs in specific functions
- Refactoring code after review
- Implementing feature changes
- Applying security patches
Quick Reference¶
| Property | Value |
|---|---|
| Tier | Community |
| Languages | Python, JavaScript, TypeScript, Java |
| Token Cost | ~50-200 tokens |
Parameters¶
| Parameter | Type | Required | Description |
|---|---|---|---|
file_path | string | ✓ | Path to file to modify |
target_type | string | ✓ | "function", "class", or "method" |
target_name | string | ✓ | Name of element to replace |
new_code | string | ✓ | Replacement code |
create_backup | bool | Create backup file (default: true) |
Example Usage¶
Prompt:
"Fix the SQL injection in authenticate_user"
Tool Call:
{
"tool": "update_symbol",
"parameters": {
"file_path": "src/auth.py",
"target_type": "function",
"target_name": "authenticate_user",
"new_code": "def authenticate_user(username: str, password: str) -> Optional[User]:\n \"\"\"Authenticate user with parameterized query.\"\"\"\n cursor.execute('SELECT * FROM users WHERE username = ?', (username,))\n return cursor.fetchone()"
}
}
Prompt:
"Update the validate method to check email format"
Tool Call:
{
"tool": "update_symbol",
"parameters": {
"file_path": "src/models/user.py",
"target_type": "method",
"target_name": "User.validate",
"new_code": "def validate(self) -> bool:\n \"\"\"Validate user data including email format.\"\"\"\n if not self.email or '@' not in self.email:\n return False\n return len(self.name) > 0"
}
}
Response Format¶
{
"data": {
"success": true,
"file_path": "src/auth.py",
"target_type": "function",
"target_name": "authenticate_user",
"backup_path": "src/auth.py.bak",
"lines_replaced": {
"start": 15,
"end": 25
},
"new_lines": {
"start": 15,
"end": 20
}
},
"tier_applied": "community",
"duration_ms": 45
}
Tier Differences¶
| Feature | Community | Pro | Enterprise |
|---|---|---|---|
| Single-file update | ✅ | ✅ | ✅ |
| Automatic backup | ✅ | ✅ | ✅ |
| Syntax validation | ✅ | ✅ | ✅ |
| Max file size | 1 MB | 10 MB | Unlimited |
| Audit logging | — | — | ✅ |
rename_symbol¶
Rename a symbol across the entire codebase.
What It Does¶
rename_symbol performs project-wide renaming:
- Finds all usages: Uses
get_symbol_referencesinternally - Updates all files: Renames in every location
- Preserves references: Updates imports, calls, and definitions
- Creates backups: For all modified files
When AI Agents Use This¶
- Refactoring for better naming
- Fixing typos in function/class names
- Standardizing naming conventions
- API migrations
Quick Reference¶
| Property | Value |
|---|---|
| Tier | Pro |
| Languages | Python, JavaScript, TypeScript, Java |
| Token Cost | ~100-300 tokens |
Parameters¶
| Parameter | Type | Required | Description |
|---|---|---|---|
file_path | string | ✓ | File containing the symbol definition |
target_type | string | ✓ | "function", "class", or "method" |
target_name | string | ✓ | Current name |
new_name | string | ✓ | New name |
create_backup | bool | Create backups (default: true) |
Example Usage¶
Prompt:
"Rename getUserData to fetchUserProfile across the codebase"
Tool Call:
{
"tool": "rename_symbol",
"parameters": {
"file_path": "src/api/users.py",
"target_type": "function",
"target_name": "getUserData",
"new_name": "fetchUserProfile"
}
}
Response Format¶
{
"data": {
"success": true,
"old_name": "getUserData",
"new_name": "fetchUserProfile",
"files_modified": [
"src/api/users.py",
"src/api/routes.py",
"src/services/user_service.py",
"tests/test_users.py"
],
"references_updated": 12,
"backups_created": [
"src/api/users.py.bak",
"src/api/routes.py.bak",
"src/services/user_service.py.bak",
"tests/test_users.py.bak"
]
},
"tier_applied": "pro",
"duration_ms": 890
}
Tier Differences¶
| Feature | Community | Pro | Enterprise |
|---|---|---|---|
| Available | — | ✅ | ✅ |
| Cross-file rename | — | ✅ | ✅ |
| Automatic backups | — | ✅ | ✅ |
| Audit logging | — | — | ✅ |
| CODEOWNERS notification | — | — | ✅ |
Common Workflows¶
Extract → Review → Update¶
1. extract_code("src/auth.py", "function", "login")
→ Get the current code
2. [AI reviews and improves code]
3. update_symbol("src/auth.py", "function", "login", new_code)
→ Apply the improvement
Analyze → Extract → Rename¶
1. analyze_code("src/api.py")
→ Find all functions
2. extract_code("src/api.py", "function", "getData")
→ Review the function
3. rename_symbol("src/api.py", "function", "getData", "fetch_data")
→ Rename to snake_case
Related Categories¶
- Analysis Tools - Understand code before extracting
- Security Tools - Scan code after modifying
- Symbolic Tools - Verify changes don't break behavior