Skip to content
Skillpedia
General coding6.2k · #14386

apply-patch

What it does

This skill applies a set of code changes as one patch using Git. It is for developers whose agent needs to change multiple files or whose simple edits keep failing to match.

When to use it

  • ✓When one change needs edits across three or more files.
  • ✓When simple find-and-replace edits keep failing because the text does not match.
  • ✓When you want to apply a patch that came from a pull request or a git diff.

Skill link

https://github.com/agentscope-ai/agentscope-java/blob/main/agentscope-examples/agents/agentscope-codingagent/src/main/resources/workspace-templates/skills/apply-patch/SKILL.md

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/agentscope-ai/agentscope-java/blob/main/agentscope-examples/agents/agentscope-codingagent/src/main/resources/workspace-templates/skills/apply-patch/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute →

Example of what to ask your AI

“Apply the same rename across the four files in this module as one patch, and check it applies cleanly first.”

5 new skills a week. 1 minute to read.

How it works

The skill writes a unified diff describing the changes, checks that it applies, and then applies it with Git all at once. If the patch is rejected, the agent reads the current lines again and rebuilds the patch.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

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

  1. Write the unified diff to a file in the sandbox (use write_file or a heredoc via execute):

    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
    
  2. Validate before applying: git apply --check changes.patch

  3. Apply: git apply changes.patch (use -p0 if paths are not a/...b/...).

  4. If git apply rejects the hunk, the surrounding context is stale — read_file the 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_file exact-match struggles.
  • Re-applying a patch produced elsewhere (e.g. from a PR or git diff).

Always run the verify-changes skill afterwards.

FAQ

Does it check the patch first?

Yes, the skill checks the patch before applying it.

What happens if the patch fails?

The agent reads the current file lines again and makes a new patch.

Is it all or nothing?

The patch is applied as one change, so it is meant to be all or nothing.

Details

Original description by the author

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.

repo: agentscope-ai/agentscope-java

Popularity

GitHub stars
6.2k
Ranking position
#14386
License
Apache-2.0
Updated
11/2/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills