Skip to main content
Glama
cexll
by cexll

batch-codex

Process multiple code tasks simultaneously for batch refactoring, automated transformations, and repetitive operations using atomic task delegation.

Instructions

Delegate multiple atomic tasks to Codex for batch processing. Ideal for repetitive operations, mass refactoring, and automated code transformations

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tasksYesArray of atomic tasks to delegate to Codex
modelNoModel to use: gpt-5-codex, gpt-5, o3, o4-mini, codex-1, codex-mini-latest, gpt-4.1
sandboxNoSandbox mode: read-only, workspace-write, danger-full-accessworkspace-write
parallelNoExecute tasks in parallel (experimental)
stopOnErrorNoStop execution if any task fails
timeoutNoMaximum execution time per task in milliseconds
workingDirNoWorking directory for execution
searchNoEnable web search for all tasks (activates web_search_request feature)
ossNoUse local Ollama server
enableFeaturesNoEnable feature flags
disableFeaturesNoDisable feature flags

Implementation Reference

  • The core handler function that parses arguments, sorts tasks by priority, executes each atomic task using executeCodex (sequentially, parallel TODO), handles errors based on stopOnError flag, provides progress updates, collects results, and returns a formatted summary report with success/failure stats.
    execute: async (args, onProgress) => {
      const {
        tasks,
        model,
        sandbox,
        parallel,
        stopOnError,
        timeout,
        workingDir,
        search,
        oss,
        enableFeatures,
        disableFeatures,
      } = args;
      const taskList = tasks as Array<{
        task: string;
        target?: string;
        priority: string;
      }>;
    
      if (!taskList || taskList.length === 0) {
        throw new Error('No tasks provided for batch execution');
      }
    
      const results: Array<{
        task: string;
        status: 'success' | 'failed' | 'skipped';
        output?: string;
        error?: string;
      }> = [];
      let failedCount = 0;
      let successCount = 0;
    
      // Sort tasks by priority
      const sortedTasks = [...taskList].sort((a, b) => {
        const priorityOrder = { high: 0, normal: 1, low: 2 };
        return (
          priorityOrder[a.priority as keyof typeof priorityOrder] -
          priorityOrder[b.priority as keyof typeof priorityOrder]
        );
      });
    
      if (onProgress) {
        onProgress(`šŸš€ Starting batch execution of ${sortedTasks.length} tasks...`);
      }
    
      // Execute tasks sequentially
      // TODO: Implement parallel execution when parallel flag is true
      for (let i = 0; i < sortedTasks.length; i++) {
        const task = sortedTasks[i];
        const taskPrompt = task.target ? `${task.task} in ${task.target}` : task.task;
    
        if (onProgress) {
          onProgress(`\n[${i + 1}/${sortedTasks.length}] Executing: ${taskPrompt}`);
        }
    
        // Skip remaining tasks if stopOnError is true and we have failures
        if (stopOnError && failedCount > 0) {
          results.push({
            task: taskPrompt,
            status: 'skipped',
            error: 'Skipped due to previous failure',
          });
          continue;
        }
    
        try {
          const result = await executeCodex(
            taskPrompt,
            {
              model: model as string,
              sandboxMode: sandbox as any,
              timeout: timeout as number,
              workingDir: workingDir as string,
              search: search as boolean,
              oss: oss as boolean,
              enableFeatures: enableFeatures as string[],
              disableFeatures: disableFeatures as string[],
            },
            undefined // No progress for individual tasks to keep output clean
          );
    
          results.push({
            task: taskPrompt,
            status: 'success',
            output: result.substring(0, 500), // Truncate for summary
          });
          successCount++;
    
          if (onProgress) {
            onProgress(`āœ… Completed: ${task.task}`);
          }
        } catch (error) {
          const errorMessage = error instanceof Error ? error.message : String(error);
          results.push({
            task: taskPrompt,
            status: 'failed',
            error: errorMessage,
          });
          failedCount++;
    
          if (onProgress) {
            onProgress(`āŒ Failed: ${task.task} - ${errorMessage}`);
          }
        }
      }
    
      // Generate summary report
      let report = `\nšŸ“Š **Batch Execution Summary**\n`;
      report += `\n- Total tasks: ${sortedTasks.length}`;
      report += `\n- Successful: ${successCount} āœ…`;
      report += `\n- Failed: ${failedCount} āŒ`;
      report += `\n- Skipped: ${sortedTasks.length - successCount - failedCount} ā­ļø`;
    
      report += `\n\n**Task Results:**\n`;
      for (const result of results) {
        const icon = result.status === 'success' ? 'āœ…' : result.status === 'failed' ? 'āŒ' : 'ā­ļø';
        report += `\n${icon} **${result.task}**`;
        if (result.status === 'success' && result.output) {
          report += `\n   Output: ${result.output.substring(0, 100)}...`;
        } else if (result.error) {
          report += `\n   Error: ${result.error}`;
        }
      }
    
      // If all tasks failed, throw an error
      if (failedCount === sortedTasks.length) {
        throw new Error(`All ${failedCount} tasks failed. See report above for details.`);
      }
    
      return report;
    },
  • Zod schema defining the input arguments for the batch-codex tool, including tasks array (each with task, target?, priority), model, sandbox mode, parallel execution flag, etc. Used as zodSchema in the tool definition.
    const batchCodexArgsSchema = z.object({
      tasks: z.array(batchTaskSchema).min(1).describe('Array of atomic tasks to delegate to Codex'),
      model: z
        .string()
        .optional()
        .describe(`Model to use: ${Object.values(MODELS).join(', ')}`),
      sandbox: z
        .string()
        .default(SANDBOX_MODES.WORKSPACE_WRITE)
        .describe(`Sandbox mode: ${Object.values(SANDBOX_MODES).join(', ')}`),
      parallel: z.boolean().default(false).describe('Execute tasks in parallel (experimental)'),
      stopOnError: z.boolean().default(true).describe('Stop execution if any task fails'),
      timeout: z.number().optional().describe('Maximum execution time per task in milliseconds'),
      workingDir: z.string().optional().describe('Working directory for execution'),
      search: z
        .boolean()
        .optional()
        .describe('Enable web search for all tasks (activates web_search_request feature)'),
      oss: z.boolean().optional().describe('Use local Ollama server'),
      enableFeatures: z.array(z.string()).optional().describe('Enable feature flags'),
      disableFeatures: z.array(z.string()).optional().describe('Disable feature flags'),
    });
  • Imports the batchCodexTool from batch-codex.tool.ts (noted as .js likely due to build config) and registers it by pushing to the toolRegistry array, making it available for MCP tool protocol.
    import { toolRegistry } from './registry.js';
    import { askCodexTool } from './ask-codex.tool.js';
    import { batchCodexTool } from './batch-codex.tool.js';
    // import { reviewCodexTool } from './review-codex.tool.js';
    import { pingTool, helpTool, versionTool } from './simple-tools.js';
    import { brainstormTool } from './brainstorm.tool.js';
    import { fetchChunkTool } from './fetch-chunk.tool.js';
    import { timeoutTestTool } from './timeout-test.tool.js';
    
    toolRegistry.push(
      askCodexTool,
      batchCodexTool,
      // reviewCodexTool,
      pingTool,
      helpTool,
      versionTool,
      brainstormTool,
      fetchChunkTool,
      timeoutTestTool
    );
  • Sub-schema for individual batch tasks, used within the main tasks array schema. Defines task description, optional target, and priority.
    const batchTaskSchema = z.object({
      task: z.string().describe('Atomic task description'),
      target: z.string().optional().describe('Target files/directories (use @ syntax)'),
      priority: z.enum(['high', 'normal', 'low']).default('normal').describe('Task priority'),
    });
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure but offers minimal details. It mentions 'batch processing' and use cases but doesn't describe critical behaviors like execution flow, error handling, output format, or resource implications. For a complex tool with 11 parameters and no annotations, this is inadequate, though not contradictory.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise with two sentences that efficiently convey purpose and ideal use cases. Every word earns its place without redundancy, and it's front-loaded with the core function. No unnecessary elaboration or waste.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (11 parameters, batch processing, no annotations, no output schema), the description is insufficient. It lacks details on execution behavior, result format, error handling, and integration with sibling tools. While concise, it doesn't provide enough context for an agent to fully understand how to invoke and interpret this tool effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents all 11 parameters. The description adds no specific parameter details beyond implying tasks involve 'atomic' operations and targets use '@ syntax.' This meets the baseline of 3 since the schema does the heavy lifting, but the description doesn't enhance understanding of parameter interactions or semantics.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose as 'Delegate multiple atomic tasks to Codex for batch processing' with specific use cases like 'repetitive operations, mass refactoring, and automated code transformations.' It distinguishes from sibling tools like 'ask-codex' by emphasizing batch processing rather than single interactions. However, it doesn't explicitly contrast with all siblings, preventing a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides implied usage context with 'Ideal for repetitive operations, mass refactoring, and automated code transformations,' which suggests when to use this tool. However, it lacks explicit guidance on when NOT to use it or clear alternatives among siblings like 'ask-codex' for single tasks. No prerequisites or exclusions are mentioned.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/cexll/codex-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server