Apply Patch
Developmentapply-patchApply Patch is an Agent Skill for development published in the agentscope-ai/agentscope-java repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.
Apply multi-file or tricky edits atomically with git apply instead of many fragile edit_file calls. Use when changing several files at once or when edit_file fails to match.
How to use this skill
Bring this guide into your coding agent with a prompt tailored to the tool you use.
- Open your project in Codex.
- Copy and paste the prompt below.
- Review files and risks before approving any action.
Inspect the Agent Skill at https://github.com/agentscope-ai/agentscope-java/blob/HEAD/agentscope-examples/agents/agentscope-codingagent/src/main/resources/workspace-templates/skills/apply-patch/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/apply-patch, but wait for my approval before writing files or running scripts.
Copying this prompt does not install or run the skill. Review third-party files before use.
Apply Patch
The built-in edit_file does an exact string match on a single file and has no fuzzy
tolerance. For multi-file changes, or when edit_file keeps failing to find the string,
construct a unified diff and apply it atomically with git.
Procedure
-
Write the unified diff to a file in the sandbox (use
write_fileor a heredoc viaexecute):diff --git a/path/to/file b/path/to/file --- a/path/to/file +++ b/path/to/file @@ -10,7 +10,7 @@ context line -old line +new line -
Validate before applying:
git apply --check changes.patch -
Apply:
git apply changes.patch(use-p0if paths are nota/...b/...). -
If
git applyrejects the hunk, the surrounding context is stale —read_filethe exact lines again, regenerate the diff with correct context, and retry.
When to prefer this
- Editing 3+ files for one logical change (atomic, all-or-nothing).
- Repetitive or whitespace-sensitive edits where
edit_fileexact-match struggles. - Re-applying a patch produced elsewhere (e.g. from a PR or
git diff).
Always run the verify-changes skill afterwards.