
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
A CLI tool and Python library for applying patches using a custom patch format designed for AI coding assistants
A CLI tool and Python library for applying patches using a custom patch format designed for AI coding assistants.
This project is based on OpenAI's original codex apply-patch tool and extends it with additional functionality.
This fork adds the following enhancements to the original OpenAI tool:
In-Memory Patch Application: New functionality to apply patches to files in memory without touching the filesystem, useful for testing and preview scenarios.
Python Library Support: Complete Python bindings using PyO3, allowing the patch functionality to be used directly from Python code.
PyPI Distribution: The library is packaged and distributed via PyPI for easy installation.
pip install codex-apply-patch
# Install Rust if you haven't already
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Clone and build
git clone https://github.com/openai/codex-apply-patch
cd codex-apply-patch
cargo build --release
# For Python development
pip install maturin
maturin develop --release
# Apply patch from stdin
echo "*** Begin Patch
*** Add File: hello.txt
+Hello, World!
*** End Patch" | codex_apply_patch
import codex_apply_patch as cap
# Apply patch to files on disk
patch = """*** Begin Patch
*** Add File: hello.py
+print("Hello, World!")
*** End Patch"""
result = cap.apply_patch(patch)
print(result)
# Apply patch in memory (new feature)
files = {
"main.py": "def main():\n print('old version')\n"
}
patch = """*** Begin Patch
*** Update File: main.py
@@
def main():
- print('old version')
+ print('new version')
*** End Patch"""
result = cap.apply_patch_in_memory(patch, files)
print("Modified files:", result.files)
print("Summary:", f"Added: {len(result.added)}, Modified: {len(result.modified)}, Deleted: {len(result.deleted)}")
# Generate patch from file contents (new feature)
original = "def hello():\n print('old version')"
new = "def hello():\n print('new version')\n print('updated!')"
patch = cap.generate_patch("main.py", original, new)
print("Generated patch:")
print(patch)
# Generate patch for multiple files (new feature)
file_changes = {
"new.py": (None, "print('new file')"), # Add file
"old.py": ("old content", None), # Delete file
"update.py": ("old", "new") # Update file
}
multi_patch = cap.generate_patch_from_files(file_changes)
print("Multi-file patch:")
print(multi_patch)
apply_patch(patch_str)
- Apply patch to files on diskapply_patch_in_memory(patch_str, files_dict)
- Apply patch to in-memory filesparse_patch(patch_str)
- Parse patch and return structure informationgenerate_patch(path, original_content, new_content)
- Generate patch for a single filegenerate_patch_from_files(files_dict)
- Generate patch for multiple filesget_tool_instructions()
- Get the CLI tool instructions for AI assistantsget_api_instructions()
- Get the patch format instructions (without CLI specifics)Licensed under the Apache License, Version 2.0. See LICENSE for details.
This project extends the original OpenAI codex apply-patch tool, which is also licensed under Apache-2.0.
FAQs
A CLI tool and Python library for applying patches using a custom patch format designed for AI coding assistants
We found that codex-apply-patch demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.