Method signature

async createPullRequest(): Promise<PullRequestResponse>

Description

The createPullRequest method allows you to create a GitHub pull request after code changes have been generated using the Codex agent. This method streamlines the process of submitting code changes for review by automatically creating a pull request with the generated modifications.

Parameters

This method takes no parameters.

Return type

TypeDescription
Promise<PullRequestResponse>Promise that resolves to a pull request response object

PullRequestResponse Interface

PropertyTypeRequiredDescription
html_urlstringYesThe URL to view the pull request on GitHub
numbernumberYesThe pull request number
branchNamestringYesThe name of the branch created for the PR
commitShastringNoThe SHA of the commit

Requirements

  • Agent Type: This method is only available when using the Codex agent
  • Initialization: The VibeKit instance must be properly initialized with Codex configuration
  • Code Generation: Code changes should be generated before creating a pull request

Error handling

The method throws errors in the following scenarios:

Agent Type Error

throw new Error("Pull request creation is only supported for the Codex agent")
  • When: Called with an agent type other than “codex”
  • Resolution: Ensure your VibeKit instance is configured with agent.type: "codex"

Initialization Error

throw new Error("CodexAgent not initialized")
  • When: The CodexAgent is not properly initialized
  • Resolution: Verify your VibeKit configuration includes valid Codex settings

Usage examples

Basic Usage

import { VibeKit } from 'vibekit';

const vibekit = new VibeKit(config);

// Generate code first
await vibekit.generateCode("Add a new user registration feature");

// Create pull request
try {
  const prResponse = await vibekit.createPullRequest();
  
  console.log(`Pull request created: ${prResponse.html_url}`);
  console.log(`PR Number: ${prResponse.number}`);
  console.log(`Branch: ${prResponse.branchName}`);
  console.log(`Commit SHA: ${prResponse.commitSha}`);
} catch (error) {
  console.error("Failed to create pull request:", error.message);
}

Notes

  • The pull request is automatically labeled with ‘codex’ or ‘claude’ to indicate it was created by the Codex or Claude agent
  • Ensure your GitHub token has the necessary permissions to create pull requests in the target repository
  • The method creates a new branch for the pull request automatically
  • Code changes must be generated before calling this method