---
title: "Apply a batch of file-level edits in an active repo session: write, replace, writeJson, delete, or move."
method: POST
path: "/v1/repo-sessions/{session_id}/edits"
tags: ["repos"]
---

# Apply a batch of file-level edits in an active repo session: write, replace, writeJson, delete, or move.

`POST /v1/repo-sessions/{session_id}/edits`

## Request

- Base URL: `https://api.kody.codes`
- URL: `https://api.kody.codes/v1/repo-sessions/{session_id}/edits`
- Auth: HTTP bearer

Apply a batch of file-level edits in an active repo session: write, replace, writeJson, delete, or move. Same-path write/replace/writeJson edits in one call compose in order against each prior result. Use `write` for whole-file replacements or for creating new files when a unified diff for `repoApplyPatch` would be brittle (for example, single-file job sources or generated package modules). A write replaces the file at `path` with `content` exactly, creates missing parent directories, and treats empty `content` as clearing the file. Each edit returns a per-file diff plus a `changed` flag. This is the file-level repo session API: use `repoRebaseSession` to merge from the published default branch. There is no git-command channel; branch, checkout, and remote operations are not available in sessions (use the git lane via `packageGetGitRemote` for full git). Each content-changing edit is subject to a 10 MiB per-file size limit on the planned result. Edits mutate the live session overlay only; pair with `repoCommit`, `repoRunChecks`, and `repoPublishSession` to validate and publish.

Org permission: `package:write`.

## Path parameters

- `session_id` string, required: Active repo session id from repoOpenSession or repoListSessions.

## Request body

- object
  - `edits` union[], required: Batch of file-level edits: write, replace, writeJson, delete, or move. Multiple content edits to the same path compose sequentially.
    - union
      - object
        - `kind` 'write', required
        - `path` string, required: Repo-relative file path to write. Existing files are overwritten; missing parent directories are created.
        - `content` string, required: Full new file content. Pass the entire file body, not a patch or diff. Empty string clears the file.
      - object
        - `kind` 'replace', required
        - `path` string, required
        - `search` string, required
        - `replacement` string
        - `options` object
          - `case_sensitive` boolean
          - `regex` boolean
          - `whole_word` boolean
          - `context_before` integer
          - `context_after` integer
          - `max_matches` integer
          - `spaces` integer
      - object
        - `kind` 'writeJson', required
        - `path` string, required
        - `value` unknown, required
        - `options` object
          - `spaces` integer
      - object
        - `kind` 'delete', required
        - `path` string, required
      - object
        - `kind` 'move', required
        - `path` string, required
        - `to` string, required
  - `dry_run` boolean: Preview edits without mutating the workspace.
  - `rollback_on_error` boolean: When true (default), roll back the batch if any edit fails. Set false to keep partial progress.

## Response `200`

Success.

- object
  - `dry_run` boolean, required
  - `total_changed` integer, required
  - `edits` object[], required
    - `path` string, required
    - `changed` boolean, required
    - `content` string, required
    - `diff` string, required

## Other responses

- `400`: Error envelope `{ "error": { "code", "message", "details"? } }`.
- `401`: Error envelope `{ "error": { "code", "message", "details"? } }`.
- `403`: Error envelope `{ "error": { "code", "message", "details"? } }`.
- `404`: Error envelope `{ "error": { "code", "message", "details"? } }`.
- `409`: Error envelope `{ "error": { "code", "message", "details"? } }`.
- `413`: Error envelope `{ "error": { "code", "message", "details"? } }`.
- `429`: Too many requests (edge IP/token limit) or an entitlement / plan-cap limit. Wait at least `Retry-After` seconds before retrying.
- `500`: Error envelope `{ "error": { "code", "message", "details"? } }`.
- `503`: Error envelope `{ "error": { "code", "message", "details"? } }`.
- `default`: Error envelope `{ "error": { "code", "message", "details"? } }`.

---

[API](https://skmtc.dev/kody/apis/kody-api.md) · [All operations](https://skmtc.dev/kody/apis/kody-api/llms.txt) · [OpenAPI document](https://skmtc.dev/kody/apis/kody-api/revisions/705f4f022728?raw)
