Code Execution

Code Execution

Execute Python code locally with marketplace API access for 90%+ token savings on bulk operations. Activates when user requests bulk operations (10+ f

Category: development Source: mhattingpete/claude-skills-marketplace

What Is Code Execution?

Code Execution is a specialized Claude Code skill designed to run Python code locally with integrated marketplace API access, enabling dramatic efficiency improvements for large-scale code and file operations. By moving computation and bulk workflow steps off the cloud model and onto your local environment, Code Execution delivers 90-99% token savings for high-volume tasks—especially when processing 10 or more files, handling complex multi-step automations, or pursuing iterative transformations across significant codebases.

This skill is particularly well-suited for scenarios where cloud-based token limits, latency, or API cost constraints would otherwise impede productivity. It provides streamlined access to core APIs for file manipulation, code analysis, batch refactoring, and version control, all within a local Python runtime invoked through Claude Code.

Why Use Code Execution?

Modern software projects often require automated manipulation of large codebases, such as renaming identifiers across hundreds of files, applying multi-stage refactoring, or extracting code metadata for auditing and documentation. Performing these operations through traditional cloud APIs can be prohibitively expensive and slow due to tokenization costs and round-trip latency.

Code Execution addresses these challenges by:

  • Token Efficiency: Reducing token consumption by 90% or more for bulk operations, enabling cost-effective processing of large projects.
  • Performance: Leveraging local execution for significantly faster operation compared to cloud-only solutions, especially for iterative or multi-step workflows.
  • API Integration: Exposing high-level APIs for the most common development tasks—filesystem access, static code analysis, transformation, and Git integration—making it easy to automate complex operations with minimal code.
  • Scalability: Handling thousands of files or complex workflows that would otherwise hit cloud service limits or require cumbersome batching.

In essence, Code Execution empowers developers to operate at scale while maintaining control, speed, and economy.

How to Get Started

Getting up and running with Code Execution is straightforward. If the skill is not already installed in your Claude Code environment, execute the provided setup script:

~/.claude/plugins/marketplaces/mhattingpete-claude-skills/execution-runtime/setup.sh

Once installed, you can access the skill's APIs by importing them in your Python code:

from execution_runtime import fs, code, transform, git

This unlocks a suite of functions for local operations. For example, to copy specific lines from one file and paste them into another:

## Copy lines 10-20 from source.py
code_block = fs.copy_lines('source.py', 10, 20)

## Paste at line 50 in target.py
fs.paste_code('target.py', 50, code_block)

For bulk refactoring, such as renaming an identifier across all Python files in the directory:

result = transform.rename_identifier('.', 'oldName', 'newName', '**/*.py')

To analyze all functions matching a pattern:

functions = code.find_functions('app.py', pattern='handle_.*')

And for Git integration:

git.git_add(['.'])
git.git_commit('feat: refactor code')

These functions are designed for high efficiency, enabling you to perform advanced workflows with minimal code and maximum performance.

Key Features

Code Execution offers a focused set of APIs tailored to the needs of developers working with large codebases:

  • Filesystem Operations (fs)

    • copy_lines(source, start, end): Copy a range of lines from a file.
    • paste_code(target, line, code_block): Paste code at a specific line.
    • search_replace(path, pattern, replacement): Apply search-and-replace in files.
    • batch_copy(src_dir, dest_dir, pattern): Copy multiple files matching a pattern.
  • Code Analysis (code)

    • find_functions(file, pattern): Extract function names matching a pattern (metadata only).
    • find_classes(file): List class definitions.
    • analyze_dependencies(file): Extract import and dependency information.
  • Transformations (transform)

    • rename_identifier(root, old, new, pattern): Rename variables, functions, or classes across files.
    • remove_debug_statements(root, pattern): Strip out debug statements.
    • batch_refactor(root, refactor_map): Apply multiple refactoring rules in one pass.
  • Git Integration (git)

    • git_add(paths): Stage changes for commit.
    • git_commit(message): Commit staged changes.
    • git_status(): Show the current status of the working directory.

All operations are optimized for batch processing and are ideal for scenarios requiring high performance and low overhead.

Best Practices

  • Use for Bulk and Complex Workflows: Activate Code Execution when dealing with ten or more files, multi-step transformations, or when performance is critical.
  • Test on Sample Data: For large-scale refactoring or file operations, test your script on a subset of files first to ensure correctness.
  • Chain Operations: Combine filesystem, code analysis, and transformation APIs for powerful automation (e.g., extract metadata, refactor, and commit in a single script).
  • Leverage Metadata: Use code analysis functions for non-invasive inspection—these return metadata only and are safe for code audit or documentation tasks.
  • Integrate with CI/CD: Scripts using Code Execution can be incorporated into continuous integration pipelines for automated code quality and transformation tasks.

Important Notes

  • Local Execution: All code runs locally; ensure your environment has the necessary permissions and dependencies.
  • Metadata Only for Analysis: The code API provides metadata extraction (e.g., function/class names), not full code introspection or execution.
  • Efficiency Threshold: The skill is designed to activate for bulk operations (10+ files) or when efficiency/performance is explicitly required.
  • API Limitations: Only the documented APIs are supported; arbitrary code execution outside these is not permitted.
  • Security Considerations: Exercise standard security practices when manipulating files or running scripts, especially in shared or production environments.

By following these guidelines and leveraging the provided APIs, you can dramatically enhance your productivity and scalability when working with large codebases using the Code Execution skill.