---
title: "Edit files in a context document tree"
method: PATCH
path: "/context-documents/tree/{tree_id}/files"
tags: ["Context Documents"]
---

# Edit files in a context document tree

`PATCH /context-documents/tree/{tree_id}/files`

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.

## Path parameters

- `tree_id` string, required

## Request body

- EditFilesRequest — 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.
  - `files` object — Map of file path → new content (content edits).
  - `renames` object — Map of old path → new path (rename edits).
  - `deletions` string[] — List of file paths to soft-delete (sticky until cleared).
  - `additions` object — Map of file path → initial content for user-declared files at paths the LLM doesn't produce. Sticky until cleared.

## Response `200`

Successful Response

- TreeResponse
  - `tree_id` string, required
  - `status` string, required
  - `version` integer, required
  - `files` TreeFile[], nullable, required
    - `path` string, required
    - `content` string, required
    - `tier` string, required
    - `team` string, nullable, required
    - `updated_at` string, required
  - `error` string, nullable, required
  - `created_at` string, date-time, required
  - `completed_at` string, date-time, nullable, required
  - `meta` object, required

## Other responses

- `422` — Validation Error

---

[API](https://skmtc.net/hyperspell/apis/hyperspell-api.md) · [All operations](https://skmtc.net/hyperspell/apis/hyperspell-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/hyperspell/hyperspell-api/versions/5721acd588e6/schema)
