insert_at
Insert content before or after a target line in a file using an anchor substring or line number, without replacing existing text.
Instructions
Insert content before or after a single target line (anchor or line number) without replacing existing content. Writes atomically.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"path": "<path>",
"new_content": "<new_content>"
},
"name": "insert_at"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Absolute or workspace-relative path to the file. | |
| anchor | No | Target line (substring, case-sensitive). Mutually exclusive with line_number. | |
| encoding | No | File encoding. Default: utf-8. Pass utf-8-sig to strip a BOM. | utf-8 |
| position | No | Where to splice relative to the target line. | after |
| line_number | No | Target line (positive = 1-based, negative = from end). Mutually exclusive with anchor. | |
| new_content | Yes | Text to insert, written byte-for-byte. The caller is responsible for any line endings needed to keep the insertion on its own line. | |
| anchor_total | No | Expected total occurrences of anchor in the file. | |
| project_root | No | Sets (and remembers) the project root for resolving relative paths for this and subsequent calls in the session. | |
| anchor_occurrence | No | Which occurrence of anchor to use (1-based). | |
| expected_content_hash | No | SHA-256 hex digest of the target line's raw bytes (including its terminator). Rejected with HASH_MISMATCH if it doesn't match. |