write_file

[codefix]

Writes a JS, TS, JSON, or JSONC workspace file with a preview diff by default and applies changes only when requested.

Why this tool exists

Full-file writes need root-bound path checks, open-document version guards, and a diff that callers can inspect before mutation.

How it helps the agent

The model can preview or apply JS/TS/JSON file replacement through the server instead of doing an unchecked shell write.

Try it locally in the TGlider playground

Parameters

NameTypeRequiredDescription
filePathstringYesWorkspace-relative or absolute file path.
textstringYesFull replacement text for the target file.
applyChangesbooleanNoApply the full-file write to disk and live workspace state instead of returning preview only.
includeDiffbooleanNoInclude a unified diff in the response.
maxDiffCharsnumberNoMaximum diff characters to return before truncating.
expectedVersionnumberNoRequired live-document version guard when the target file is open.

Examples

Preview a full-file write without mutating disk

Request
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "write_file",
    "arguments": {
      "filePath": "src/app.ts",
      "text": "export const value = 2;\\n"
    }
  }
}

Response Notes

Returns changed/created/applied flags, optional unified diff metadata, live-document version state, and refresh mode after applied writes.

↑/↓ NavigateEnter OpenSpace Expand