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 operations, which interrupts the conversation flow during security testing, CTF (Capture The Flag) competitions, and penetration testing. This project provides tools to clean up these refusals from session histories and inject specialized prompts to reduce the likelihood of future refusals.

How it works

The tool operates through two primary mechanisms:

  1. Session Cleaning: It scans session files (JSONL or SQLite formats) for refusal responses using a two-tier detection strategy (strong phrase matching and weak keyword matching). 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 a context-aware replacement. It also removes reasoning/thinking blocks to clean the history.
  2. Prompt Injection: It modifies configuration files or creates dedicated workspaces to inject CTF-specific system prompts. For Codex, it can create a separate profile or modify the global config. For Claude Code and OpenCode, it sets up dedicated workspaces with project-level 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 security-related tasks and want to avoid session interruptions caused by AI safety filters.

Highlights

  • Multi-platform support: Works with Codex CLI, Claude Code, and OpenCode.
  • AI-powered rewriting: Uses LLMs to generate seamless replacements for refused responses based on conversation context.
  • Flexible injection: Supports both profile-based and global prompt injection for Codex.
  • Comprehensive UI: Includes a Web UI for session management, visual diffing of changes, and prompt editing.
  • Safety features: Automatically creates backups before cleaning and supports one-click restoration.

Related

  • Project
  • Dispatch
  • Project
  • Project
  • Project