replace_in_body
Replace a specific snippet inside a function or method body without altering surrounding code. Scopes the match to the target body to prevent accidental matches elsewhere.
Instructions
Replace a byte-identical snippet inside a named function/method body, without touching the surrounding code. The match is scoped to the target's body so accidental matches elsewhere in the file cannot happen.
Raises if the snippet is not found, or if it appears more than once in the body (include more surrounding context to disambiguate).
Use this when: You need to change a specific statement or block inside a
large function body without rewriting the whole body. The single biggest
token-saver for long functions with ~30 similar lines where you only want
to change one of them.
Don't use this when: You're replacing the entire body -> use
replace_function_body. You need to change a sub-expression inside a
method chain that string matching can't uniquely locate -> use the default
Edit tool instead.
Example: target="init" old_snippet="viper.BindPFlag("port", cmd.Flags().Lookup("port"))" new_snippet="viper.BindPFlag("port", cmd.PersistentFlags().Lookup("port"))"
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | ||
| target | Yes | ||
| old_snippet | Yes | ||
| new_snippet | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |