> ## Documentation Index
> Fetch the complete documentation index at: https://docs.base44.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Import a Claude Code or Codex session on an imported app

> <Info>This API is in beta. Endpoints, fields, and behavior may still change, so avoid depending on it in production.</Info>

Imports a Claude Code or Codex session into an imported app as a Base Code session, with the session's conversation in its chat and its Git branches as the session's branches. You continue the work there with the AI. The `base44 sessions import` CLI command calls this endpoint.

Send the session file as `file` in a `multipart/form-data` body. Base Code reads a Claude Code transcript, the `.jsonl` file under `~/.claude/projects/`, or a Codex rollout, the `rollout-*.jsonl` file under `~/.codex/sessions/`. The file can be up to 50 MB.

The conversation is cut at the prompt that asked for the import, so that prompt and everything after it are left out. Only typed messages, the images pasted into them, and the AI's replies are kept, and at most the newest 400 turns are written. Thinking, tool arguments, and tool output, including its screenshots, are dropped. The newest 20 pasted PNG, JPEG, GIF, and WebP images are attached to their messages. A message whose images weren't imported, because there were more or they couldn't be read or stored, says how many.

Send the Git branches the session worked on as `branches`. Each must be in the app's GitHub repository. Base Code adopts each one except the default branch as it is, as a branch of the same session, so stop working on them locally. The session's current branch is `source_branch` when it's one of them, and the last one when it isn't. Without `branches`, the session continues on the branch it's on when that branch is in the repository and isn't the default branch. If Base Code already has an active branch with one of those names in another session, the import is refused and nothing is written. When there's no such branch, Base Code creates a new branch named after the session's first message. It starts from the session's branch when that's in the repository, and from the default branch when it isn't. `continued` and `source_ref` say which one happened. On an app without Base Code sessions, only one branch is imported: `source_branch` when it's in `branches`, else the last one.

Importing a session again adds only what's new. When the same session was imported before into a Base Code session that still exists, Base Code writes only the messages that come after the ones it already has, after anything said there since, and sets `reimported` to `true`. `turn_count` then counts the new messages, so `0` means the session was already up to date. The code isn't touched: the branches already follow the session's pushed commits, and `branches` not yet in the session join it. If the session was deleted, the import creates a new one as above.

Authenticate with a personal access token, sent as `Authorization: Bearer <token>`. Where the user isn't signed in, such as on a cloud machine, send the one-time import key that Base Code's Import session dialog creates in its place. The key starts with `b44imp_`, works once and only for the app it was created for, and expires after 10 minutes. The import then runs as the user who opened the dialog.

Send an `Idempotency-Key` header, such as a UUID, and repeat it when you retry after a lost response, a `409` `conflict`, or a `5xx`. A retry with the same key, file, `source_branch`, `branches`, and artifacts returns the first import's response and writes nothing. Only a successful import is remembered, for 24 hours, so a retry after an error imports again. An upload with an import key can't be retried at all: the key works once, so a retry gets a `401`.



## OpenAPI

````yaml /developers/references/app-management/app-management-openapi.json post /api/apps/{app_id}/imported/session-imports
openapi: 3.1.0
info:
  title: Base44 App Management API
  version: 1.0.0
servers:
  - url: https://app.base44.com
security:
  - PersonalAccessTokenAuth: []
paths:
  /api/apps/{app_id}/imported/session-imports:
    post:
      summary: Import a Claude Code or Codex session on an imported app
      description: >-
        <Info>This API is in beta. Endpoints, fields, and behavior may still
        change, so avoid depending on it in production.</Info>


        Imports a Claude Code or Codex session into an imported app as a Base
        Code session, with the session's conversation in its chat and its Git
        branches as the session's branches. You continue the work there with the
        AI. The `base44 sessions import` CLI command calls this endpoint.


        Send the session file as `file` in a `multipart/form-data` body. Base
        Code reads a Claude Code transcript, the `.jsonl` file under
        `~/.claude/projects/`, or a Codex rollout, the `rollout-*.jsonl` file
        under `~/.codex/sessions/`. The file can be up to 50 MB.


        The conversation is cut at the prompt that asked for the import, so that
        prompt and everything after it are left out. Only typed messages, the
        images pasted into them, and the AI's replies are kept, and at most the
        newest 400 turns are written. Thinking, tool arguments, and tool output,
        including its screenshots, are dropped. The newest 20 pasted PNG, JPEG,
        GIF, and WebP images are attached to their messages. A message whose
        images weren't imported, because there were more or they couldn't be
        read or stored, says how many.


        Send the Git branches the session worked on as `branches`. Each must be
        in the app's GitHub repository. Base Code adopts each one except the
        default branch as it is, as a branch of the same session, so stop
        working on them locally. The session's current branch is `source_branch`
        when it's one of them, and the last one when it isn't. Without
        `branches`, the session continues on the branch it's on when that branch
        is in the repository and isn't the default branch. If Base Code already
        has an active branch with one of those names in another session, the
        import is refused and nothing is written. When there's no such branch,
        Base Code creates a new branch named after the session's first message.
        It starts from the session's branch when that's in the repository, and
        from the default branch when it isn't. `continued` and `source_ref` say
        which one happened. On an app without Base Code sessions, only one
        branch is imported: `source_branch` when it's in `branches`, else the
        last one.


        Importing a session again adds only what's new. When the same session
        was imported before into a Base Code session that still exists, Base
        Code writes only the messages that come after the ones it already has,
        after anything said there since, and sets `reimported` to `true`.
        `turn_count` then counts the new messages, so `0` means the session was
        already up to date. The code isn't touched: the branches already follow
        the session's pushed commits, and `branches` not yet in the session join
        it. If the session was deleted, the import creates a new one as above.


        Authenticate with a personal access token, sent as `Authorization:
        Bearer <token>`. Where the user isn't signed in, such as on a cloud
        machine, send the one-time import key that Base Code's Import session
        dialog creates in its place. The key starts with `b44imp_`, works once
        and only for the app it was created for, and expires after 10 minutes.
        The import then runs as the user who opened the dialog.


        Send an `Idempotency-Key` header, such as a UUID, and repeat it when you
        retry after a lost response, a `409` `conflict`, or a `5xx`. A retry
        with the same key, file, `source_branch`, `branches`, and artifacts
        returns the first import's response and writes nothing. Only a
        successful import is remembered, for 24 hours, so a retry after an error
        imports again. An upload with an import key can't be retried at all: the
        key works once, so a retry gets a `401`.
      operationId: create_session_import_api_apps__app_id__imported_session_imports_post
      parameters:
        - name: app_id
          in: path
          required: true
          schema:
            type: string
            description: ID of the imported app to import the session into.
            title: App Id
          description: ID of the imported app to import the session into.
          example: 6820f3a4e7b91d003c45a1f1
        - name: Idempotency-Key
          in: header
          required: false
          schema:
            type: string
            minLength: 8
            maxLength: 100
            description: >-
              A value you generate for this import, 8 to 100 characters, such as
              a UUID. Send the same value when you retry the import, and a new
              one for every other import. A retry with the same value, file,
              `source_branch`, `branches`, and artifacts within 24 hours returns
              the first response instead of importing again. Keys are scoped to
              the user and the app.
            title: Idempotency-Key
          description: >-
            A value you generate for this import, 8 to 100 characters, such as a
            UUID. Send the same value when you retry the import, and a new one
            for every other import. A retry with the same value, file,
            `source_branch`, `branches`, and artifacts within 24 hours returns
            the first response instead of importing again. Keys are scoped to
            the user and the app.
          example: 5d0e2a9c-6f1b-4c3e-8a7d-2b9f0c1e4a6d
        - name: X-Active-Branch-Id
          in: header
          required: false
          schema:
            type: string
            description: >-
              ID of the branch the editor shows. Used when `branch_id` is
              omitted, for users who work on protected-main branches.
            title: X-Active-Branch-Id
          description: >-
            ID of the branch the editor shows. Used when `branch_id` is omitted,
            for users who work on protected-main branches.
          example: 68f1a2b3c4d5e6f708192a3b
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/SessionImportUpload'
      responses:
        '200':
          description: The Base Code session and branch the session was imported into.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SessionImportResponse'
              example:
                branch_id: 6820f3a4e7b91d003c45a1f3
                branch_name: fix-login-redirect
                source: claude_code
                turn_count: 42
                branch_url: >-
                  /apps/6820f3a4e7b91d003c45a1f1/editor/preview?branch=fix-login-redirect
                session_id: 6820f3a4e7b91d003c45a1f5
                session_url: >-
                  /apps/6820f3a4e7b91d003c45a1f1/editor/preview?session=6820f3a4e7b91d003c45a1f5
                continued: true
                source_ref: fix-login-redirect
                reimported: false
        '400':
          description: '`invalid_request`: The file is empty.'
          content:
            application/json:
              examples:
                invalid_request:
                  summary: invalid_request
                  value:
                    error:
                      code: invalid_request
                      message: Cannot upload empty file
                      details: {}
              schema:
                $ref: '#/components/schemas/StandardErrorEnvelope'
        '401':
          description: >-
            `unauthenticated`: The credentials are missing or invalid, or were
            sent as an `api_key` query parameter. An import key also gets this
            when it's invalid, expired, or already used, or when the user who
            created it has signed out since.
          content:
            application/json:
              examples:
                unauthenticated:
                  summary: unauthenticated
                  value:
                    error:
                      code: unauthenticated
                      message: This import key is invalid, expired or already used.
                      details: {}
              schema:
                $ref: '#/components/schemas/StandardErrorEnvelope'
        '403':
          description: >-
            `forbidden`: The credential's user doesn't have write access to the
            app, or the import key was created for another app. A read-only
            personal access token is refused, and so is a workspace API key.
            `route_does_not_accept_keys`: A workspace API key that runs as its
            workspace's owner is refused.
          content:
            application/json:
              examples:
                forbidden:
                  summary: forbidden
                  value:
                    error:
                      code: forbidden
                      message: This import key belongs to another app.
                      details: {}
              schema:
                $ref: '#/components/schemas/StandardErrorEnvelope'
        '404':
          description: >-
            `not_found`: The app doesn't exist, isn't an imported app, or
            session import isn't available for it, or the Base Code session the
            import key was created for was deleted.
          content:
            application/json:
              examples:
                not_found:
                  summary: not_found
                  value:
                    error:
                      code: not_found
                      message: Session import isn't available for this app.
                      details: {}
              schema:
                $ref: '#/components/schemas/StandardErrorEnvelope'
        '409':
          description: >-
            `branch_exists`: Base Code already has an active branch for one of
            the session's branches in another Base Code session, and nothing was
            written. `details.branch_name` and `details.branch_url` point at it.
            `repository_not_connected`: The app isn't connected to its GitHub
            repository. `conflict`: The app or its repository changed while the
            branch was being created. Retry the import with the same
            `Idempotency-Key`. `idempotency_key_mismatch`: The `Idempotency-Key`
            was already used with a different file, `source_branch`, `branches`,
            or artifacts. `idempotency_key_in_use`: An import with the same
            `Idempotency-Key` is still running. Retry it shortly.
            `session_changed`: The session was imported into an active branch
            before, but its earlier messages changed since, so Base Code can't
            tell which ones are new. Nothing was written. Import it into a new
            branch from Base Code's Import session dialog. `wrong_session`: The
            import key was created to add newer messages to the branch in
            `details.branch_url`, and this session isn't the one imported into
            it, or the key was created for a Base Code session and this session
            was already imported into the one in `details.session_url`. Nothing
            was written. `session_has_import`: The import key was created for a
            Base Code session that already has another Claude Code or Codex
            session imported into it. Nothing was written. `details.session_id`
            and `details.session_url` point at it. Import into a new session
            instead. `branch_busy`: The branch the session was imported into is
            still running a turn. Retry when it finishes.
            `auth_required_for_workspace`, `sso_required_for_workspace`, or
            `mfa_required_for_workspace`: The app's workspace needs the user who
            created the import key to sign in again.
          content:
            application/json:
              examples:
                branch_exists:
                  summary: branch_exists
                  value:
                    error:
                      code: branch_exists
                      message: Base Code already has a branch for fix-login-redirect.
                      details:
                        branch_name: fix-login-redirect
                        branch_url: >-
                          /apps/6820f3a4e7b91d003c45a1f1/editor/preview?branch=fix-login-redirect
                repository_not_connected:
                  summary: repository_not_connected
                  value:
                    error:
                      code: repository_not_connected
                      message: Connect this app to its GitHub repository first.
                      details: {}
                idempotency_key_mismatch:
                  summary: idempotency_key_mismatch
                  value:
                    error:
                      code: idempotency_key_mismatch
                      message: >-
                        This Idempotency-Key was already used with a different
                        file, source_branch, branches or artifacts.
                      details: {}
                idempotency_key_in_use:
                  summary: idempotency_key_in_use
                  value:
                    error:
                      code: idempotency_key_in_use
                      message: >-
                        An import with this Idempotency-Key is still running.
                        Retry shortly.
                      details: {}
                session_changed:
                  summary: session_changed
                  value:
                    error:
                      code: session_changed
                      message: >-
                        This session changed since it was imported into
                        fix-login-redirect, so its newer messages can't be added
                        there. Import it into a new branch from Base Code's
                        Import session dialog.
                      details:
                        branch_name: fix-login-redirect
                        branch_url: >-
                          /apps/6820f3a4e7b91d003c45a1f1/editor/preview?branch=fix-login-redirect
                wrong_session:
                  summary: wrong_session
                  value:
                    error:
                      code: wrong_session
                      message: >-
                        This isn't the session fix-login-redirect came from. Run
                        the import in that session.
                      details:
                        branch_name: fix-login-redirect
                        branch_url: >-
                          /apps/6820f3a4e7b91d003c45a1f1/editor/preview?branch=fix-login-redirect
                session_has_import:
                  summary: session_has_import
                  value:
                    error:
                      code: session_has_import
                      message: >-
                        This session already has an imported session. Import it
                        into a new session instead.
                      details:
                        session_id: 6820f3a4e7b91d003c45a1f5
                        session_url: >-
                          /apps/6820f3a4e7b91d003c45a1f1/editor/preview?session=6820f3a4e7b91d003c45a1f5
                branch_busy:
                  summary: branch_busy
                  value:
                    error:
                      code: branch_busy
                      message: >-
                        fix-login-redirect is still working. Wait for it to
                        finish and import again.
                      details:
                        branch_name: fix-login-redirect
                        branch_url: >-
                          /apps/6820f3a4e7b91d003c45a1f1/editor/preview?branch=fix-login-redirect
              schema:
                $ref: '#/components/schemas/StandardErrorEnvelope'
        '411':
          description: >-
            `content_length_required`: The request has no `Content-Length`
            header.
          content:
            application/json:
              examples:
                content_length_required:
                  summary: content_length_required
                  value:
                    error:
                      code: content_length_required
                      message: Content-Length header required
                      details: {}
              schema:
                $ref: '#/components/schemas/StandardErrorEnvelope'
        '413':
          description: >-
            `file_too_large`: The file is larger than 50 MB, or the whole
            request is larger than 95 MB.
          content:
            application/json:
              examples:
                file_too_large:
                  summary: file_too_large
                  value:
                    error:
                      code: file_too_large
                      message: File too large (max 52428800 bytes)
                      details: {}
              schema:
                $ref: '#/components/schemas/StandardErrorEnvelope'
        '422':
          description: >-
            `unsupported_file`: The file isn't a Claude Code or Codex session,
            or it has nothing to import before the import prompt.
            `repository_mismatch`: The session was recorded in a different
            repository from the app's. `branch_not_on_github`: A branch in
            `branches` isn't in the app's GitHub repository, and nothing was
            written. `details.branch_name` names it. `invalid_request`: `file`
            is missing, `source_branch` or a branch in `branches` is longer than
            255 characters, a branch in `branches` is empty, there are more than
            20 `branches`, or `Idempotency-Key` is shorter than 8 or longer than
            100 characters.
          content:
            application/json:
              examples:
                unsupported_file:
                  summary: unsupported_file
                  value:
                    error:
                      code: unsupported_file
                      message: This file isn't a Claude Code or Codex session.
                      details: {}
                branch_not_on_github:
                  summary: branch_not_on_github
                  value:
                    error:
                      code: branch_not_on_github
                      message: >-
                        fix-login-copy isn't a branch of the app's GitHub
                        repository. Push it and import again.
                      details:
                        branch_name: fix-login-copy
                repository_mismatch:
                  summary: repository_mismatch
                  value:
                    error:
                      code: repository_mismatch
                      message: This session was recorded in a different repository.
                      details: {}
                invalid_request:
                  summary: invalid_request
                  value:
                    error:
                      code: invalid_request
                      message: Invalid request
                      details: {}
              schema:
                $ref: '#/components/schemas/StandardErrorEnvelope'
        '429':
          description: >-
            `rate_limited`: The base limit is 6 imports per minute, scoped to
            the user, and reported in the `X-RateLimit-*` headers. Retry after
            the number of seconds in `Retry-After`. See [Rate
            limits](/developers/references/apps-api/get-started/rate-limits) for
            the multiplier your plan gets.
          content:
            application/json:
              examples:
                rate_limited:
                  summary: rate_limited
                  value:
                    error:
                      code: rate_limited
                      message: Rate limit exceeded.
                      details: {}
              schema:
                $ref: '#/components/schemas/StandardErrorEnvelope'
        '503':
          description: >-
            `authority_unavailable`: GitHub couldn't confirm access to the
            repository, usually because it is rate-limiting.
            `database_unavailable`: the data cluster did not answer in time.
            Retry after the `Retry-After` seconds.
          content:
            application/json:
              examples:
                authority_unavailable:
                  summary: authority_unavailable
                  value:
                    error:
                      code: authority_unavailable
                      message: >-
                        GitHub could not confirm repository access. Retry the
                        import.
                      details: {}
                database_unavailable:
                  summary: database_unavailable
                  value:
                    error:
                      code: database_unavailable
                      message: Database temporarily unavailable, please retry
                      details: {}
              schema:
                $ref: '#/components/schemas/StandardErrorEnvelope'
          headers:
            Retry-After:
              description: Seconds to wait before retrying.
              schema:
                type: integer
      security:
        - PersonalAccessTokenAuth:
            - full_access
components:
  schemas:
    SessionImportUpload:
      properties:
        file:
          type: string
          format: binary
          title: File
          description: >-
            The session file, a Claude Code `.jsonl` transcript or a Codex
            `rollout-*.jsonl` file of up to 50 MB.
        source_branch:
          anyOf:
            - type: string
              maxLength: 255
            - type: 'null'
          title: Source Branch
          description: >-
            The Git branch the session is on now. It wins over the branch
            recorded in the file, which can predate a push. Leave it out to use
            the file's branch.
          examples:
            - fix-login-redirect
        branches:
          items:
            type: string
            maxLength: 255
            minLength: 1
          type: array
          maxItems: 20
          title: Branches
          description: >-
            The Git branches the session worked on, up to 20, each 1 to 255
            characters. Repeat the part for each branch. Each must be in the
            app's GitHub repository, or the import fails with a 422
            `branch_not_on_github` and nothing is written. Each one except the
            default branch becomes a branch of the Base Code session. Leave it
            out to use `source_branch`, or the file's branch.
          default: []
          examples:
            - - fix-login-redirect
              - fix-login-copy
      type: object
      required:
        - file
      title: SessionImportUpload
      description: A Claude Code or Codex session to import.
    SessionImportResponse:
      properties:
        branch_id:
          type: string
          title: Branch Id
          description: ID of the Base Code branch the session was imported into.
          examples:
            - 6820f3a4e7b91d003c45a1f3
        branch_name:
          type: string
          title: Branch Name
          description: >-
            Name of that branch. When `continued` is `true`, it's the session's
            own Git branch.
          examples:
            - fix-login-redirect
        source:
          type: string
          enum:
            - claude_code
            - codex
          title: Source
          description: >-
            The tool that recorded the session. Either `"claude_code"` or
            `"codex"`.
          examples:
            - claude_code
        turn_count:
          type: integer
          title: Turn Count
          description: Number of messages written to the branch's chat by this import.
          examples:
            - 42
        branch_url:
          type: string
          title: Branch Url
          description: >-
            Path of the branch in the app editor. Append it to the Base44
            address to open it.
          examples:
            - >-
              /apps/6820f3a4e7b91d003c45a1f1/editor/preview?branch=fix-login-redirect
        session_id:
          type: string
          title: Session Id
          description: >-
            ID of the Base Code session the conversation was imported into.
            `branch_id` is its current branch.
          examples:
            - 6820f3a4e7b91d003c45a1f5
        session_url:
          type: string
          title: Session Url
          description: >-
            Path of the session in the app editor. Append it to the Base44
            address to open it.
          examples:
            - >-
              /apps/6820f3a4e7b91d003c45a1f1/editor/preview?session=6820f3a4e7b91d003c45a1f5
        continued:
          type: boolean
          title: Continued
          description: >-
            Whether the session continues on its own branch. The value is `true`
            when Base Code adopted the session's branch and `false` when it
            created a new branch from `source_ref`.
          examples:
            - true
        source_ref:
          type: string
          title: Source Ref
          description: >-
            Git branch the Base Code branch comes from. It's the session's
            branch when that's in the repository, and the repository's default
            branch when it isn't.
          examples:
            - fix-login-redirect
        reimported:
          type: boolean
          title: Reimported
          description: >-
            Whether this session was imported into the branch before. When
            `true`, only the messages added since then were written and
            `turn_count` counts them, so `0` means the branch was already up to
            date.
          default: false
          examples:
            - false
      type: object
      required:
        - branch_id
        - branch_name
        - source
        - turn_count
        - branch_url
        - session_id
        - session_url
        - continued
        - source_ref
      title: SessionImportResponse
    StandardErrorEnvelope:
      properties:
        error:
          $ref: '#/components/schemas/StandardError'
          description: What went wrong.
      type: object
      required:
        - error
      title: StandardErrorEnvelope
      description: The error body returned in the standard envelope.
    StandardError:
      properties:
        code:
          type: string
          title: Code
          description: >-
            Stable machine-readable cause of the failure. Match on this, not on
            `message`.
          example: not_found
        message:
          type: string
          title: Message
          description: Human-readable explanation. It isn't a stable contract.
          example: App not found
        details:
          additionalProperties: true
          type: object
          title: Details
          description: >-
            Structured context for the failure, or an empty object when there's
            none.
          example: {}
      type: object
      required:
        - code
        - message
      title: StandardError
  securitySchemes:
    PersonalAccessTokenAuth:
      type: http
      scheme: bearer
      description: >-
        Personal access token, sent as `Authorization: Bearer <token>`. Each
        operation lists the permission it needs: `read_only` or `full_access`. A
        full-access token can call every operation. A read-only token can call
        only the operations that list `read_only`; anything else returns 403
        `read_only_credential_route_not_allowed`.

````

## Related topics

- [Managing branches and pull requests in Base Code](https://docs.base44.com/base-code/branches-and-pull-requests.md)
- [sessions import](https://docs.base44.com/developers/references/cli/commands/sessions-import.md)
- [Launch coding session on an imported app](https://docs.base44.com/api-reference/launch-coding-session-on-an-imported-app.md)
- [Get coding session on an imported app](https://docs.base44.com/api-reference/get-coding-session-on-an-imported-app.md)
- [Cancel coding session on an imported app](https://docs.base44.com/api-reference/cancel-coding-session-on-an-imported-app.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.