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

# Edit files in a context document tree

> Edit files in a tree.

Supports three edit kinds — all persist to the `tree_edits` table so
they survive subsequent regens:

- `files`: content edits (map of path → new content)
- `renames`: rename edits (map of old path → new path)
- `deletions`: soft-delete (list of paths)

Editable when status is COMPLETED or PUBLISHED. PROCESSING is rejected
(the workflow is mid-write); FAILED has nothing meaningful to edit.
The tree's `files` JSONB is updated in-place so the dashboard sees
immediate results without waiting for the next regen.



## OpenAPI

````yaml https://app.stainlessapi.com/api/spec/documented/hyperspell.yaml patch /context-documents/tree/{tree_id}/files
openapi: 3.1.0
info:
  title: Hyperspell API
  summary: >-
    Hyperspell is the memory layer for AI apps and agents. Through the API, you
    can add memories, connect data sources to index them in real-time, and
    search memories with our natural language query engine.
  termsOfService: https://hyperspell.com/blog/tos
  contact:
    name: Hyperspell
    url: https://hyperspell.com/
    email: hello@hyperspell.com
  version: 0.32.1
servers:
  - url: https://api.hyperspell.com
    description: Production
security:
  - APIKey: []
    AsUser: []
paths:
  /context-documents/tree/{tree_id}/files:
    patch:
      tags:
        - Context Documents
      summary: Edit files in a context document tree
      description: |-
        Edit files in a tree.

        Supports three edit kinds — all persist to the `tree_edits` table so
        they survive subsequent regens:

        - `files`: content edits (map of path → new content)
        - `renames`: rename edits (map of old path → new path)
        - `deletions`: soft-delete (list of paths)

        Editable when status is COMPLETED or PUBLISHED. PROCESSING is rejected
        (the workflow is mid-write); FAILED has nothing meaningful to edit.
        The tree's `files` JSONB is updated in-place so the dashboard sees
        immediate results without waiting for the next regen.
      operationId: edit_tree_files_context_documents_tree__tree_id__files_patch
      parameters:
        - name: tree_id
          in: path
          required: true
          schema:
            type: string
            title: Tree Id
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/EditFilesRequest'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TreeResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - APIKey: []
        - AsUser: []
components:
  schemas:
    EditFilesRequest:
      properties:
        files:
          additionalProperties:
            type: string
          type: object
          title: Files
          description: Map of file path → new content (content edits).
        renames:
          additionalProperties:
            type: string
          type: object
          title: Renames
          description: Map of old path → new path (rename edits).
        deletions:
          items:
            type: string
          type: array
          title: Deletions
          description: List of file paths to soft-delete (sticky until cleared).
        until_next_regen:
          type: boolean
          title: Until Next Regen
          description: >-
            When true, the CONTENT edits in this request auto-clear after the
            next successful tree regeneration instead of pinning the file
            indefinitely. Rename/delete/add edits are unaffected.
          default: false
        additions:
          additionalProperties:
            type: string
          type: object
          title: Additions
          description: >-
            Map of file path → initial content for user-declared files at paths
            the LLM doesn't produce. Sticky until cleared.
      type: object
      title: EditFilesRequest
      description: |-
        Request body for editing files in a tree.

        All three edit kinds persist to the `tree_edits` table so they survive
        subsequent regens. Editable when status is COMPLETED or PUBLISHED;
        `files` / `renames` / `deletions` can all be sent in a single call.
    TreeResponse:
      properties:
        tree_id:
          type: string
          title: Tree Id
        status:
          type: string
          title: Status
        version:
          type: integer
          title: Version
        files:
          anyOf:
            - items:
                $ref: '#/components/schemas/TreeFile'
              type: array
            - type: 'null'
          title: Files
        error:
          anyOf:
            - type: string
            - type: 'null'
          title: Error
        created_at:
          type: string
          format: date-time
          title: Created At
        completed_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Completed At
        meta:
          additionalProperties: true
          type: object
          title: Meta
        generating:
          anyOf:
            - $ref: '#/components/schemas/TreeGenerating'
            - type: 'null'
      type: object
      required:
        - tree_id
        - status
        - version
        - files
        - error
        - created_at
        - completed_at
        - meta
      title: TreeResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    TreeFile:
      properties:
        path:
          type: string
          title: Path
        content:
          type: string
          title: Content
        tier:
          type: string
          title: Tier
        team:
          anyOf:
            - type: string
            - type: 'null'
          title: Team
        updated_at:
          type: string
          title: Updated At
        status:
          anyOf:
            - type: string
            - type: 'null'
          title: Status
        error:
          anyOf:
            - type: string
            - type: 'null'
          title: Error
        provenance:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Provenance
      type: object
      required:
        - path
        - content
        - tier
        - team
        - updated_at
      title: TreeFile
    TreeGenerating:
      properties:
        tree_id:
          type: string
          title: Tree Id
        status:
          type: string
          enum:
            - processing
            - failed
          title: Status
        created_at:
          type: string
          format: date-time
          title: Created At
        error:
          anyOf:
            - type: string
            - type: 'null'
          title: Error
        progress:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Progress
      type: object
      required:
        - tree_id
        - status
        - created_at
      title: TreeGenerating
      description: >-
        Sidecar describing an in-flight (or just-failed) regeneration.


        Present only on the dashboard path (``include_published=true``) when a
        newer

        PROCESSING/FAILED row exists behind the served ready tree — the served
        body

        stays the last COMPLETED/PUBLISHED tree so the brain never blanks out

        mid-regen, and this block is how the UI knows to show a progress banner.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    APIKey:
      type: http
      description: >-
        API Key or JWT User Token. If using an API Key, set the X-As-User header
        to act as a specific user. A JWT User Token is always scoped to a
        specific user.
      scheme: bearer
      bearerFormat: Bearer <token>
    AsUser:
      type: apiKey
      description: >-
        Optionally set this header to act as a specific user when using an API
        Key, equivalent to first exchanging the API Key for a User Token
      in: header
      name: X-As-User

````