Skip to main content
Find relevant code across large codebases in seconds using morph-warp-grep. Minimal setup: import the tool and run. Requires rg (ripgrep) installed and available on PATH when using the local provider.
Requires rg (ripgrep) installed and available on PATH when using the local provider.

Why use Warp-Grep?

Warp-Grep Performance
@swyx and @cognition pin P(breaking_flow) at +10% every 1s. For coding applications this means speed is important when the human is in the loop.

Quick Start

  • MorphClient
  • Anthropic
  • OpenAI
  • Vercel AI SDK
  • Standalone Client
import { MorphClient } from '@morphllm/morphsdk';

const morph = new MorphClient({ apiKey: process.env.MORPH_API_KEY });

// Simple - defaults to LocalRipgrepProvider
const result = await morph.warpGrep.execute({
  query: 'Find authentication middleware',
  repoRoot: '.'
});

if (result.success) {
  for (const ctx of result.contexts) {
    console.log(`File: ${ctx.file}`);
    console.log(ctx.content);
  }
}

Pricing

TypePrice
Input$0.40 per 1M tokens
Output$0.40 per 1M tokens

Response Types

Both direct usage and tool usage return the same response structure:
  • Success Response
  • Error Response
interface WarpGrepResult {
  success: true;
  contexts: Array<{
    file: string;    // File path relative to repo root
    content: string; // Content of the relevant code section
  }>;
  summary: string;   // Summary of what was found
}

Handling Results

const result = await morph.warpGrep.execute({
  query: 'Find authentication middleware',
  repoRoot: '.'
});

if (result.success) {
  console.log(`Found ${result.contexts.length} relevant code sections`);
  
  for (const ctx of result.contexts) {
    console.log(`\n--- ${ctx.file} ---`);
    console.log(ctx.content);
  }
  
  console.log(`\nSummary: ${result.summary}`);
} else {
  console.error(`Search failed: ${result.error}`);
}

Customize tool description

Override the default tool description to tailor it for your use case:
  • MorphClient
  • Standalone
import { MorphClient } from '@morphllm/morphsdk';

const morph = new MorphClient({ apiKey: process.env.MORPH_API_KEY });

const grepTool = morph.openai.createWarpGrepTool({
  repoRoot: '.',
  description: 'Use this tool when you know what you are looking for in the codebase.'
});

Optional: Customize provider

Use a custom provider to have your agent backend run remote grep and remote read on sandboxes like E2B, Modal, Daytona, and similar platforms.

With MorphClient

Pass a custom provider via the provider option:
import { MorphClient, CommandExecProvider } from '@morphllm/morphsdk';

const morph = new MorphClient({ apiKey: process.env.MORPH_API_KEY });

// Create your custom provider (see examples below)
const myProvider = new CommandExecProvider({ ... });

const result = await morph.warpGrep.execute({
  query: 'Find authentication middleware',
  repoRoot: '.',
  provider: myProvider  // Override default LocalRipgrepProvider
});

With Tool Adapters

  • E2B
  • Daytona
import { Sandbox } from "@e2b/code-interpreter"
import { CommandExecProvider } from "@morphllm/morphsdk/tools/warp-grep"
import { createMorphWarpGrepTool } from '@morphllm/morphsdk/tools/warp-grep/anthropic';
import path from "path"

type ExecResult = { stdout: string; stderr: string; exitCode: number }

interface E2BProviderOptions {
  sandbox: Sandbox
  localDir: string
  remoteDir: string
}

async function createE2BProvider(options: E2BProviderOptions) {
    const {
        sandbox,
        localDir,
        remoteDir
    } = options

    await sandbox.commands.run("sudo apt-get update && sudo apt-get install -y ripgrep", { cwd: remoteDir })

    const run = async (
        cmd: string,
        args: string[],
        options?: { cwd?: string; env?: Record<string, string> }
    ): Promise<ExecResult> => {
        const fullCmd = [cmd, ...args].join(" ")
        const cwd = options?.cwd || remoteDir

        const result = await sandbox.commands.run(fullCmd, {
            cwd,
            envs: options?.env,
        })
        
        return {
            stdout: result.stdout,
            stderr: result.stderr,
            exitCode: result.exitCode,
        }
    }

    const pathMap = (localPath: string): string => {
        if (localPath.startsWith(localDir)) {
            return localPath.replace(localDir, remoteDir)
        }
        if (localPath.startsWith(remoteDir)) {
            return localPath
        }
        return `${remoteDir}/${localPath.replace(/^\//, "")}`
    }

    const provider = new CommandExecProvider({
        run,
        pathMap,
        cwd: remoteDir,
        excludes: [".git", "node_modules"],
    })

    return {
        provider
    }
}

const mySandbox = await Sandbox.create()

const { provider } = await createE2BProvider({
    sandbox: mySandbox,
    localDir: path.resolve('.'),
    remoteDir: "/home/user/workspace",
})

const grepTool = createMorphWarpGrepTool({
    repoRoot: path.resolve('.'),
    provider,
    apiKey: process.env.MORPH_API_KEY,
}); 
Make sure that your sandbox has rg (ripgrep).