Code Features Overview

AI-powered code editing and external CLI tool integrations for PraisonAI

Code Features

PraisonAI provides powerful code editing capabilities and integrations with external AI coding CLI tools.

Features

Quick Start

Code Editing Tools

python
from praisonai.code import (
    set_workspace,
    code_read_file,
    code_write_file,
    code_apply_diff,
    code_execute_command,
    CODE_TOOLS
)

# Set the workspace
set_workspace("/path/to/project")

# Read a file
content = code_read_file("src/main.py")

# Apply a diff
diff = """
<<<<<<< SEARCH
def old_function():
    pass
=======
def new_function():
    return "updated"
>>>>>>> REPLACE
"""
result = code_apply_diff("src/main.py", diff)

External CLI Integrations

python
from praisonai.integrations import (
    ClaudeCodeIntegration,
    GeminiCLIIntegration,
    CodexCLIIntegration,
    CursorCLIIntegration
)

# Create an integration
claude = ClaudeCodeIntegration(workspace="/path/to/project")

# Execute a coding task
result = await claude.execute("Refactor the auth module")

# Use as an agent tool
from praisonai import Agent
tool = claude.as_tool()
agent = Agent(tools=[tool])

As a native async agent tool

Preferred when the agent runs on agent.astart(...) (or any async entrypoint) — the tool is awaited directly on the running loop with no thread hop.

python
from praisonaiagents import Agent
from praisonai.integrations import ClaudeCodeIntegration

claude = ClaudeCodeIntegration(workspace="/path/to/project")

agent = Agent(
    name="Code Assistant",
    tools=[claude.as_async_tool()],   # registers as `claude_atool`
)

await agent.astart("Refactor the auth module")

as_async_tool() was added in PraisonAI PR #4022; as_tool() still works and is now also safe to call from inside an async agent runtime.

Performance

All integrations are designed with zero performance impact:

  • Lazy Loading: Modules are only imported when used
  • Availability Caching: CLI availability checks are cached
  • Async Execution: Non-blocking subprocess execution
  • Import Time: < 1ms verified in tests

CLI Usage

bash
# Use external agents from CLI
praisonai "Refactor the code" --external-agent claude
praisonai "Analyze codebase" --external-agent gemini
praisonai "Fix bugs" --external-agent codex
praisonai "Add tests" --external-agent cursor