ryfineZ/codex-session-patcher

A lightweight Python tool to clean AI refusal responses from Codex CLI session files

What it solves

AI coding tools like Codex, Claude Code, and OpenCode often refuse requests involving security-sensitive operations, which interrupts the conversation flow during security testing, CTF (Capture The Flag) competitions, or penetration testing. This project prevents these interruptions by cleaning up refusal messages from session histories and injecting specialized contexts to reduce the likelihood of refusals from the start.

How it works

The tool employs two primary strategies:

  1. Session Cleaning: It scans session logs (JSONL or SQLite formats) for refusal patterns using a two-tier detection strategy. It can then replace these refusals with cooperative content, either using a safe default text or by calling an LLM (via OpenAI, Ollama, or OpenRouter) to generate context-aware replacements. It also erases reasoning/thinking blocks to clean the output.
  2. Prompt Injection: It modifies the configuration of the AI tools to inject security-testing contexts. For Codex, it creates specific profiles or modifies global settings; for Claude Code and OpenCode, it creates dedicated CTF workspaces with specialized instruction files (like CLAUDE.md or AGENTS.md).

Who it’s for

Security researchers, CTF players, and penetration testers who use AI coding assistants to help with vulnerability analysis, exploit development, or reverse engineering.

Highlights

  • Multi-Platform Support: Works with Codex CLI, Claude Code, and OpenCode.
  • AI-Powered Rewriting: Uses LLMs to rewrite both session refusals and user prompts to make them more acceptable to the AI.
  • Visual Management: Includes a Web UI for session list management, side-by-side diff views of cleaned sessions, and prompt editing.
  • Automated CTF Workflows: Provides built-in templates for various security tasks (Web, Pwn, Reverse, Crypto, etc.) that automatically match the task type.
  • Safety Features: Automatically creates backups before cleaning and supports one-click restoration.

Related

  • Dispatch
  • Project
  • Project
  • Dispatch
  • Project