> ## Documentation Index
> Fetch the complete documentation index at: https://codegeninc-codegen-bot-sdk-docs-2-0.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Codebase

> This class provides the main entrypoint for most programs to analyzing and manipulating codebases.

export const Attribute = ({type, description}) => <div className="pl-4 py-6 first:pt-3 dark:border-zinc-300/[0.06] text-sm font-normal">
    <div className="inline-grid grid-cols-[auto_auto] gap-1 font-mono py-2">
      {type}
    </div>
    <p className="mt-2">{description}</p>
  </div>;

export const GithubLinkNote = ({link}) => <Info>
      <div className="flex gap-2 items-center">View Source on <a target="_blank" rel="noopener noreferrer" href={link}>Github</a></div>
   </Info>;

export const HorizontalDivider = ({light = false}) => <div className="divide-y">
        <div className={`divide-y ${light ? "dark:border-zinc-300/[0.06]" : "border-zinc-600"}`}></div>
        <div className={`divide-y ${light ? "dark:border-zinc-300/[0.06]" : "border-zinc-600"}`}></div>
    </div>;

export const Return = ({return_type, description}) => <div className="pl-6 divide-y">
    <h4 className="font-bold">Returns</h4>
    <div className="dark:border-zinc-300/[0.06] ">
        <div className="py-6 first:pt-3 text-sm font-normal">
            <div className="flex gap-4 items-center">
                <div className="inline-grid grid-cols-[auto_auto] gap-1 font-mono py-2">
                    {return_type}
                </div>
            </div>
            <p className="mt-2">{description}</p>
        </div>
    </div>
  </div>;

export const ParameterWrapper = ({children}) => <div className="pl-6 divide-y">
    <h4 className="font-bold">Parameters</h4>
    <div className="divide-y dark:border-zinc-300/[0.06]">
      {children}
    </div>
  </div>;

export const Parameter = ({name, type, description, defaultValue}) => <div className="py-6 first:pt-3 dark:border-zinc-300/[0.06] text-sm font-normal">
    <div className="flex justify-between items-start font-mono">
      <div className="flex gap-4 items-start">
        <div className="flex gap-1 items-center text-sm text-primary mt-2">
          {name}
        </div>
        <div className="inline-grid grid-cols-[auto_auto] gap-1 py-2">
          {type}
        </div>
      </div>

      <div className="flex-shrink-0 mt-2">
        {defaultValue ? <div className="flex gap-1 items-center text-sm border border-purple-500 px-2 py-0.5 rounded">
            <span className="text-zinc-500">default:</span>
            <span className="text-purple-500">{defaultValue}</span>
          </div> : <span className="text-sm border border-purple-500 px-2 py-0.5 rounded">
            required
          </span>}
      </div>
    </div>
    <p className="mt-2">{description}</p>
  </div>;

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/codebase.py#L117-L1566" />

## Attributes

<HorizontalDivider />

### <span className="text-primary">classes</span>

<HorizontalDivider light={true} />

<Attribute type={ <><span>list[</span> <a href="/api-reference/core/Class" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Class</a> <span>]</span></> } description="List of all Classes in the codebase." />

### <span className="text-primary">codeowners</span>

<HorizontalDivider light={true} />

<Attribute type={ <><span>list[</span> <a href="/api-reference/core/CodeOwner" style={ {fontWeight: "inherit", fontSize: "inherit"} }>CodeOwner</a> <span>[</span> <a href="/api-reference/core/SourceFile" style={ {fontWeight: "inherit", fontSize: "inherit"} }>SourceFile</a> <span>]]</span></> } description="List all CodeOnwers in the codebase." />

### <span className="text-primary">current\_commit</span>

<HorizontalDivider light={true} />

<Attribute type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">GitCommit | None</code> } description="Returns the current Git commit that is checked out in the repository." />

### <span className="text-primary">default\_branch</span>

<HorizontalDivider light={true} />

<Attribute type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The default branch of this repository." />

### <span className="text-primary">directories</span>

<HorizontalDivider light={true} />

<Attribute type={ <><span>list[</span> <a href="/api-reference/core/Directory" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Directory</a> <span>]</span></> } description="List all directories in the codebase." />

### <span className="text-primary">exports</span>

<HorizontalDivider light={true} />

<Attribute type={ <><span>list[</span> <a href="/api-reference/typescript/TSExport" style={ {fontWeight: "inherit", fontSize: "inherit"} }>TSExport</a> <span>]</span></> } description="Returns a list of all Export nodes in the codebase." />

### <span className="text-primary">external\_modules</span>

<HorizontalDivider light={true} />

<Attribute type={ <><span>list[</span> <a href="/api-reference/core/ExternalModule" style={ {fontWeight: "inherit", fontSize: "inherit"} }>ExternalModule</a> <span>]</span></> } description="Returns a list of all external modules in the codebase." />

### <span className="text-primary">functions</span>

<HorizontalDivider light={true} />

<Attribute type={ <><span>list[</span> <a href="/api-reference/core/Function" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Function</a> <span>]</span></> } description="List of all Functions in the codebase." />

### <span className="text-primary">github</span>

<HorizontalDivider light={true} />

<Attribute type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">RepoOperator</code> } description="Access GitHub operations through the repo operator." />

### <span className="text-primary">global\_vars</span>

<HorizontalDivider light={true} />

<Attribute type={ <><span>list[</span> <a href="/api-reference/core/Assignment" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Assignment</a> <span>]</span></> } description="List of all GlobalVars in the codebase." />

### <span className="text-primary">imports</span>

<HorizontalDivider light={true} />

<Attribute type={ <><span>list[</span> <a href="/api-reference/core/Import" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Import</a> <span>]</span></> } description="Returns a list of all Import nodes in the codebase." />

### <span className="text-primary">interfaces</span>

<HorizontalDivider light={true} />

<Attribute type={ <><span>list[</span> <a href="/api-reference/typescript/TSInterface" style={ {fontWeight: "inherit", fontSize: "inherit"} }>TSInterface</a> <span>]</span></> } description="Retrieves all interfaces in the codebase." />

### <span className="text-primary">language</span>

<HorizontalDivider light={true} />

<Attribute type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">ProgrammingLanguage</code> } description="The programming language of the repository." />

### <span className="text-primary">name</span>

<HorizontalDivider light={true} />

<Attribute type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The name of the repository." />

### <span className="text-primary">repo\_path</span>

<HorizontalDivider light={true} />

<Attribute type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">Path</code> } description="The path to the repository." />

### <span className="text-primary">symbols</span>

<HorizontalDivider light={true} />

<Attribute type={ <><span>list[</span> <a href="/api-reference/core/Symbol" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Symbol</a> <span>]</span></> } description="List of all top-level Symbols (Classes, Functions, etc.) in the codebase. Excludes Class" />

### <span className="text-primary">types</span>

<HorizontalDivider light={true} />

<Attribute type={ <><span>list[</span> <a href="/api-reference/typescript/TSTypeAlias" style={ {fontWeight: "inherit", fontSize: "inherit"} }>TSTypeAlias</a> <span>]</span></> } description="List of all Types in the codebase (Typescript only)." />

## Methods

<HorizontalDivider />

### <span className="text-primary">ai</span>

Generates a response from the AI based on the provided prompt, target, and context.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/codebase.py#L1196-L1283" />

<ParameterWrapper>
  <Parameter name="prompt" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The text prompt to send to the AI." defaultValue="" />

  <Parameter name="target" type={ <><a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>| None</span></> } description="An optional editable object (like a function, class, etc.) that provides the main focus for the AI's response." defaultValue="None" />

  <Parameter name="context" type={ <><a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>| list[</span> <a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>] | dict[str,</span> <a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>| list[</span> <a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>]] | None</span></> } description="Additional context to help inform the AI's response." defaultValue="None" />

  <Parameter name="model" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The AI model to use for generating the response. Defaults to &#x22;gpt-4o&#x22;." defaultValue="&#x22;gpt-4o&#x22;" />
</ParameterWrapper>

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The generated response from the AI." />

### <span className="text-primary">checkout</span>

Checks out a git branch or commit and syncs the codebase graph to the new state.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/codebase.py#L865-L909" />

<ParameterWrapper>
  <Parameter name="commit" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str | GitCommit | None</code> } description="Hash or GitCommit object to checkout. Cannot be used with branch." defaultValue="None" />

  <Parameter name="branch" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str | None</code> } description="Name of branch to checkout. Cannot be used with commit." defaultValue="None" />

  <Parameter name="create_if_missing" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="If True, creates the branch if it doesn't exist. Defaults to False." defaultValue="False" />

  <Parameter name="remote" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="If True, attempts to pull from remote when checking out branch. Defaults to False." defaultValue="False" />
</ParameterWrapper>

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">CheckoutResult</code> } description="The result of the checkout operation." />

### <span className="text-primary">commit</span>

Commits all staged changes to the codebase graph and synchronizes the graph with the filesystem if specified.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/codebase.py#L803-L815" />

<ParameterWrapper>
  <Parameter name="sync_graph" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="Whether to synchronize the graph after committing changes. Defaults to True." defaultValue="True" />
</ParameterWrapper>

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">None</code> } description="" />

### <span className="text-primary">create\_directory</span>

Creates a directory at the specified path.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/codebase.py#L511-L527" />

<ParameterWrapper>
  <Parameter name="dir_path" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The path where the directory should be created." defaultValue="" />

  <Parameter name="exist_ok" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="If True, don't raise an error if the directory already exists. Defaults to False." defaultValue="False" />

  <Parameter name="parents" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="If True, create any necessary parent directories. Defaults to False." defaultValue="False" />
</ParameterWrapper>

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">None</code> } description="" />

### <span className="text-primary">create\_file</span>

Creates a new file in the codebase with specified content.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/codebase.py#L476-L509" />

<ParameterWrapper>
  <Parameter name="filepath" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The path where the file should be created." defaultValue="" />

  <Parameter name="content" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The content of the file to be created. Defaults to empty string." defaultValue="&#x22;&#x22;" />

  <Parameter name="sync" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="Whether to sync the graph after creating the file. Defaults to True." defaultValue="True" />
</ParameterWrapper>

<Return return_type={ <><a href="/api-reference/core/SourceFile" style={ {fontWeight: "inherit", fontSize: "inherit"} }>SourceFile</a></> } description="The newly created file object." />

### <span className="text-primary">create\_pr</span>

Creates a pull request from the current branch to the repository's default branch.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/codebase.py#L974-L1006" />

<ParameterWrapper>
  <Parameter name="title" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The title for the pull request" defaultValue="" />

  <Parameter name="body" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The description/body text for the pull request" defaultValue="" />
</ParameterWrapper>

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">PullRequest</code> } description="The created GitHub pull request object" />

### <span className="text-primary">create\_pr\_comment</span>

Create a comment on a pull request

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/codebase.py#L1538-L1540" />

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">None</code> } description="" />

### <span className="text-primary">create\_pr\_review\_comment</span>

Create a review comment on a pull request.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/codebase.py#L1542-L1566" />

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">None</code> } description="" />

### <span className="text-primary">files</span>

A list property that returns all files in the codebase.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/codebase.py#L286-L322" />

<Return return_type={ <><span>list[</span> <a href="/api-reference/core/SourceFile" style={ {fontWeight: "inherit", fontSize: "inherit"} }>SourceFile</a> <span>] | list[</span> <a href="/api-reference/core/File" style={ {fontWeight: "inherit", fontSize: "inherit"} }>File</a> <span>]</span></> } description="A sorted list of source files in the codebase." />

### <span className="text-primary">find\_by\_span</span>

Finds editable objects that overlap with the given source code span.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/codebase.py#L1293-L1308" />

<ParameterWrapper>
  <Parameter name="span" type={ <><a href="/api-reference/core/Span" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Span</a></> } description="The span object containing the filepath and byte range to search within." defaultValue="" />
</ParameterWrapper>

<Return return_type={ <><span>list[</span> <a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>]</span></> } description="A list of Editable objects that overlap with the given span." />

### <span className="text-primary">from\_files</span>

Creates a Codebase instance from multiple files.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/codebase.py#L1448-L1528" />

<Return return_type={ <><a href="/api-reference/core/Codebase" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Codebase</a></> } description="A Codebase instance initialized with the provided files" />

### <span className="text-primary">from\_repo</span>

Fetches a codebase from GitHub and returns a Codebase instance.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/codebase.py#L1331-L1398" />

<ParameterWrapper>
  <Parameter name="repo_name" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The name of the repository in format &#x22;owner/repo&#x22;" defaultValue="" />

  <Parameter name="tmp_dir" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">Optional[str]</code> } description="The directory to clone the repo into. Defaults to /tmp/codegen" defaultValue="&#x22;/tmp/codegen&#x22;" />

  <Parameter name="commit" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">Optional[str]</code> } description="The specific commit hash to clone. Defaults to HEAD" defaultValue="None" />

  <Parameter name="shallow" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="Whether to do a shallow clone. Defaults to True" defaultValue="" />

  <Parameter name="language" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">Literal["python", "typescript"] | ProgrammingLanguage | None</code> } description="The programming language of the repo. Defaults to None." defaultValue="" />

  <Parameter name="config" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">CodebaseConfig</code> } description="Configuration for the codebase. Defaults to pre-defined defaults if None." defaultValue="" />

  <Parameter name="secrets" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">SecretsConfig</code> } description="Configuration for the secrets. Defaults to empty values if None." defaultValue="" />
</ParameterWrapper>

<Return return_type={ <><a href="/api-reference/core/Codebase" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Codebase</a></> } description="A Codebase instance initialized with the cloned repository" />

### <span className="text-primary">from\_string</span>

Creates a Codebase instance from a string of code.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/codebase.py#L1401-L1445" />

<Return return_type={ <><a href="/api-reference/core/Codebase" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Codebase</a></> } description="A Codebase instance initialized with the provided code Example: >>> # Python code >>> code = &#x22;def add(a, b): return a + b&#x22; >>> codebase = Codebase.from_string(code, language=&#x22;python&#x22;) >>> # TypeScript code >>> code = &#x22;function add(a: number, b: number): number { return a + b; }&#x22; >>> codebase = Codebase.from_string(code, language=&#x22;typescript&#x22;)" />

### <span className="text-primary">get\_class</span>

Returns a class that matches the given name.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/codebase.py#L687-L709" />

<ParameterWrapper>
  <Parameter name="class_name" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The name of the class to find." defaultValue="" />

  <Parameter name="optional" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="If True, return None when class is not found instead of raising ValueError. Defaults to False." defaultValue="False" />
</ParameterWrapper>

<Return return_type={ <><a href="/api-reference/core/Class" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Class</a> <span>| None</span></> } description="The class with the given name, or None if optional=True and class not found." />

### <span className="text-primary">get\_directory</span>

Returns Directory by `dir_path`, or full path to the directory from codebase root.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/codebase.py#L609-L629" />

<ParameterWrapper>
  <Parameter name="dir_path" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The path to the directory to retrieve." defaultValue="" />

  <Parameter name="optional" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="If True, return None when directory is not found. If False, raise ValueError." defaultValue="False" />
</ParameterWrapper>

<Return return_type={ <><a href="/api-reference/core/Directory" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Directory</a> <span>| None</span></> } description="The Directory object if found, None if optional=True and directory not found." />

### <span className="text-primary">get\_file</span>

Retrieves a file from the codebase by its filepath.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/codebase.py#L551-L594" />

<ParameterWrapper>
  <Parameter name="filepath" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The path to the file, relative to the codebase root." defaultValue="" />

  <Parameter name="optional" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="If True, return None if file not found. If False, raise ValueError." defaultValue="False" />

  <Parameter name="ignore_case" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="If True, ignore case when checking for file existence. Defaults to False." defaultValue="False" />
</ParameterWrapper>

<Return return_type={ <><a href="/api-reference/core/SourceFile" style={ {fontWeight: "inherit", fontSize: "inherit"} }>SourceFile</a> <span>| None</span></> } description="The source file if found, None if optional=True and file not found." />

### <span className="text-primary">get\_function</span>

Retrieves a function from the codebase by its name.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/codebase.py#L711-L738" />

<ParameterWrapper>
  <Parameter name="function_name" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The name of the function to retrieve." defaultValue="" />

  <Parameter name="optional" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="If True, returns None when function is not found instead of raising ValueError." defaultValue="False" />
</ParameterWrapper>

<Return return_type={ <><a href="/api-reference/core/Function" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Function</a> <span>| None</span></> } description="The matching function if found. If optional=True and no match is found, returns None." />

### <span className="text-primary">get\_modified\_symbols\_in\_pr</span>

Get all modified symbols in a pull request

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/codebase.py#L1530-L1536" />

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">tuple[str, dict[str, str], list[str], str]</code> } description="" />

### <span className="text-primary">get\_relative\_path</span>

Calculates a relative path from one file to another, removing the extension from the target file.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/codebase.py#L748-L779" />

<ParameterWrapper>
  <Parameter name="from_file" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The file path from which the relative path will be computed." defaultValue="" />

  <Parameter name="to_file" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The file path (whose extension will be removed) to which the relative path will be computed." defaultValue="" />
</ParameterWrapper>

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The relative path from `from_file` to `to_file` (with the extension removed from `to_file`)." />

### <span className="text-primary">get\_symbol</span>

Returns a Symbol by name from the codebase.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/codebase.py#L644-L669" />

<ParameterWrapper>
  <Parameter name="symbol_name" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The name of the symbol to find." defaultValue="" />

  <Parameter name="optional" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="If True, returns None when symbol is not found. If False, raises ValueError. Defaults to False." defaultValue="False" />
</ParameterWrapper>

<Return return_type={ <><a href="/api-reference/core/Symbol" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Symbol</a> <span>| None</span></> } description="The matched Symbol if found, None if not found and optional=True." />

### <span className="text-primary">get\_symbols</span>

Retrieves all symbols in the codebase that match the given symbol name.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/codebase.py#L671-L685" />

<ParameterWrapper>
  <Parameter name="symbol_name" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The name of the symbols to retrieve." defaultValue="" />
</ParameterWrapper>

<Return return_type={ <><span>list[</span> <a href="/api-reference/core/Symbol" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Symbol</a> <span>]</span></> } description="A list of Symbol objects that match the given name, sorted alphabetically." />

### <span className="text-primary">git\_commit</span>

Stages + commits all changes to the codebase and git.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/codebase.py#L785-L801" />

<ParameterWrapper>
  <Parameter name="message" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The commit message" defaultValue="" />

  <Parameter name="verify" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="Whether to verify the commit before committing. Defaults to False." defaultValue="False" />
</ParameterWrapper>

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">GitCommit | None</code> } description="The commit object if changes were committed, None otherwise." />

### <span className="text-primary">has\_directory</span>

Returns a boolean indicating if a directory exists in the codebase.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/codebase.py#L596-L607" />

<ParameterWrapper>
  <Parameter name="dir_path" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The path to the directory to check for, relative to the codebase root." defaultValue="" />
</ParameterWrapper>

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="True if the directory exists in the codebase, False otherwise." />

### <span className="text-primary">has\_file</span>

Determines if a file exists in the codebase.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/codebase.py#L529-L545" />

<ParameterWrapper>
  <Parameter name="filepath" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The filepath to check for existence." defaultValue="" />

  <Parameter name="ignore_case" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="If True, ignore case when checking for file existence. Defaults to False." defaultValue="False" />
</ParameterWrapper>

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="True if the file exists in the codebase, False otherwise." />

### <span className="text-primary">has\_symbol</span>

Returns whether a symbol exists in the codebase.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/codebase.py#L631-L642" />

<ParameterWrapper>
  <Parameter name="symbol_name" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The name of the symbol to look for." defaultValue="" />
</ParameterWrapper>

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="True if a symbol with the given name exists in the codebase, False otherwise." />

### <span className="text-primary">reset</span>

Resets the codebase by

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/codebase.py#L846-L863" />

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">None</code> } description="" />

### <span className="text-primary">set\_ai\_key</span>

Sets the OpenAI key for the current Codebase instance.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/codebase.py#L1285-L1291" />

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">None</code> } description="" />

### <span className="text-primary">set\_session\_options</span>

Sets the session options for the current codebase.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/codebase.py#L1310-L1328" />

<ParameterWrapper>
  <Parameter name="max_transactions" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">int, optional</code> } description="The maximum number of transactions" defaultValue="" />

  <Parameter name="max_seconds" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">int, optional</code> } description="The maximum duration in seconds for a session" defaultValue="" />

  <Parameter name="max_ai_requests" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">int, optional</code> } description="The maximum number of AI requests" defaultValue="" />
</ParameterWrapper>

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">None</code> } description="" />

### <span className="text-primary">should\_fix</span>

Returns True if the flag should be fixed based on the current mode and active group.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/codebase.py#L1060-L1074" />

<ParameterWrapper>
  <Parameter name="flag" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">CodeFlag</code> } description="The code flag to check." defaultValue="" />
</ParameterWrapper>

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="True if the flag should be fixed, False if it should be ignored. Returns False in find mode. Returns True if no active group is set. Returns True if the flag's hash exists in the active group hashes." />

### <span className="text-primary">visualize</span>

Visualizes a NetworkX graph or Plotly figure.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/codebase.py#L1012-L1025" />

<ParameterWrapper>
  <Parameter name="G" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">Graph | go.Figure</code> } description="A NetworkX graph or Plotly figure to visualize" defaultValue="" />

  <Parameter name="root" type={ <><a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>| str | int | None</span></> } description="The root node to visualize around. When specified, the visualization will be centered on this node. Defaults to None." defaultValue="None" />
</ParameterWrapper>

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">None</code> } description="" />
