Skip to main content
AgentDetox — a shield around persistent agent context

AgentDetox

Protect your agent's memory: block known-risk writes, detect suspicious changes, and clean up unwanted instructions.

Protection for the memory, instructions, skills and config your coding agent trusts across sessions.

PyPI CI Python License: Apache-2.0

Quick start · How it works · Evidence · Documentation · Interactive demo

English (primary) · 简体中文


A poisoned page can become tomorrow's memory. An install script can change CLAUDE.md while your agent is busy elsewhere. AgentDetox checks writes to persistent context, records changes with source evidence, and lets you remove selected added lines or restore an earlier version, with a backup either way. A cleanup changes the file, not what a running session has already read: start a new session in that client afterwards.

0.5.0 is published on PyPI and GitHub. The project is in preview: Claude Code is supported; Codex and Cursor hooks are experimental; OpenClaw has no hook of its own, so nothing is checked as it writes; its files are checked from the command line and at the session start of the other clients. Development supports native Windows with Python 3.12 and Git Bash, alongside macOS/Linux. Windows offline validation covers the installed-wheel lifecycle; real-client and sustained daily-use validation remain separate. See Windows evidence. Native Windows latency measurements still exceed several existing budgets; the performance record retains failures and paired optimization results.

Check planned writes; notice context changes; review diffs and source evidence; restore an earlier version with a backup

Quick start

Requires Python 3.11+. Install with uv or pipx:

On Windows, install Git for Windows for Claude's Bash tool. PowerShell can launch these CLI commands, but AgentDetox's shell-write analysis supports Git Bash syntax; PowerShell/cmd.exe syntax is not supported. Windows uses background NLI workers, without a resident model server. Native development commands are in CONTRIBUTING.md.

uv tool install agentdetox
agentdetox demo

The demo uses real hook handlers in a temporary folder: a planted write is denied, shell tampering is noticed, and the file is restored. It makes no model calls and consumes no agent subscription usage.

Connect Claude Code using one of these routes:

Claude Code plugin

Run in your terminal:

claude plugin marketplace add chriswu727/agentdetox
claude plugin install agentdetox@agentdetox

The plugin uses your installed agentdetox. Without it, the plugin needs uvx to fetch and run its pinned release from PyPI. Installing the CLI above also gives you review and recovery commands.

Direct hooks in Claude Code settings
agentdetox install claude-code --apply

This backs up and updates your Claude Code settings. AgentDetox follows CLAUDE_CONFIG_DIR. Use this route as an alternative to the plugin.

Restart Claude Code, then check the installation:

agentdetox doctor
agentdetox status

doctor reports missing, outdated or duplicate hooks. The first session scans existing context before recording recovery checkpoints. Installation, upgrades and removal →

How it works

  1. Before a write: check planned Write/Edit content and recognized shell writes. High-risk rule matches are denied; flagged text you supplied yourself asks instead, except hidden text. Changes to hooks, MCP servers, permissions and other guardrails need approval.
  2. After a write or shell tool: retain versions and source evidence. Shell completion or failure triggers a scoped comparison and a review notice for changed context. The interval identifies when a change happened; it does not prove which process wrote it.
  3. At session start: reconcile changes made outside the agent. Flagged content is reported until reviewed. Newly added runnable settings are mentioned once and stay in review.
  4. When you review: inspect the diff and evidence, accept that exact version, dismiss a finding, remove selected added lines, or restore the version before a change. Recovery checks for newer edits and backs up the current file.

Watched Claude context includes CLAUDE.md, parent instructions, auto memory, rules, skills, subagents, commands, output styles, hook scripts, settings and MCP config. Rules cover English and Chinese. Full coverage and behavior →

A review you can act on

agentdetox review --interactive           # browse this project's files in a terminal
agentdetox review --project . --since 7d  # recent project and auto-memory changes
agentdetox review C42                    # inspect a change id from your review list
agentdetox restore C42                   # preview the version before that change
agentdetox restore C42 --apply           # back up the current file and restore

C42 is an example id; use the id shown by your own review list. Acceptance and dismissal never grant permanent trust to a source. Recovery restores a whole recorded version, which can also undo benign additions. For a newly added config entry, removing it with the tool that added it is often preferable to restoring the whole settings file.

agentdetox clean C42 lists added lines. Use agentdetox clean C42 --lines 3,5-7 to preview removing only the lines you selected from memory, instructions or skills, while keeping other content and non-conflicting later edits. Run the exact apply command printed by that preview; a changed file invalidates it. Cleanup backs up the current file and rescans the result. It does not automatically select copied text, restore overwritten text or judge factual correctness. The terminal review also offers this action. Review, settings and recovery details →

Evidence and limits

AgentDetox is a layer of checks and recovery, not a security boundary or a factual verifier. Paraphrased payloads and plausible false facts can pass. Arbitrary scripts and dynamically built paths may escape pre-execution checks; scoped post-tool observation can detect persistent changes afterwards. Detached background writes need later reconciliation. Hooks fail open on errors, which remain visible in doctor and status; a write to agent context that could not be checked asks instead. Code running as your user can alter the hooks or store.

  • Offline regression gallery: authored prevention, monitoring and byte-exact recovery cases, plus a separate 21-case acceptance set with three explicit semantic misses. These are not real-world accuracy estimates. Protocol and results.
  • Claude Code release-candidate lab, 2026-11-10. Across 12 scenarios with and without AgentDetox, 23 of 24 scenario/arm checks passed. The remaining check required a verbatim edit that the smaller models did not complete. AgentDetox stayed quiet in all seven attempts at that scenario. The lab recorded no hook errors or landed attacks. Results and retries.
  • Development latency, 2026-11-10: 100 samples per case on one Mac, no NLI inference. The latest run, on the 0.5.0 release candidate, passed all 12 original budgets: Bash pre/post P95 126.7 ms; startup with 1,000 unchanged files 132.6 ms; four concurrent writes plus a Bash pair 293.6 ms. Earlier scan-load measurements and Windows budget failures remain retained. Method, raw data and limits.
  • 100k synthetic inventory, 2026-11-10: full/incremental inspection, cancellation/resumption and scoped dismissal/reopening passed. About 419 MB of notes took 316 s for first inspection, 15.3 s unchanged, with 46.8 MB process peak RSS. Known semantic misses remain explicit; these are local module measurements, not production-support or real-world accuracy claims. Protocol and raw report.

Source matching is evidence of copied text, not proof of malicious intent or human authorship. An empty rescan does not certify a file as safe. In 0.5.0, agentdetox library inspects an existing folder of memory files and cleans reviewed lines; it is measured against a separate scale protocol, whose 1k/10k/100k tiers are not current production-support guarantees. Full limitations · Threat model

Local processing, sensitive history

Hooks and checks make no network calls. There is no telemetry or account. Installation, the plugin's uvx fallback and optional model downloads need network access. File copies and source evidence stay in ~/.agentdetox; copies of config files can contain secrets. Back up the entire store, including objects/, and review retention before deleting history. Privacy and stored data →

More workflows

  • Other agents: experimental Codex and Cursor hooks; no OpenClaw plugin, and Cursor has not been run. In 0.5.0, agentdetox agent inspect finds the memory, rules and skill files of Claude Code, Codex, Cursor and OpenClaw where each client keeps or relocates them and records what is flagged as review items, so clean and restore work without any hook. It checks files, not whether a client delivers hook events or whether remembered text is true. Integration matrix.
  • Contradiction checks: optional local NLI, recorded in the background by default because of false positives. Setup and limits.
  • Existing memory libraries (0.5.0): agentdetox library scan <folder> inventories a folder you choose, inspects its text files with the per-file rules, resumes after interruption and never calls a file clean; clean M<ID> removes reviewed lines with a backup, and library dismiss sets a false positive aside for one file's exact bytes without allowlisting it. Library guide.
  • RAG knowledge bases: agentdetox scan for hidden instructions and suspicious passage clusters; trace ranks leads behind a wrong answer. Scanner guide.

Documentation and development

Documentation index · User guide · Changelog · Roadmap · Contributing

./scripts/check.sh  # lint, type checks and tests

See architecture and design decisions before changing the hook or recovery path. The offline gallery makes no model calls; real-agent lab runs require explicit authorization and a session cap.

Licensed under Apache-2.0.

Metadata

Release files for agentdetox 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for agentdetox 0.5.0
File Size Uploaded Provenance Actions
agentdetox-0.5.0.tar.gz 426.0 kB With provenance Details for agentdetox-0.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for agentdetox 0.5.0
File Interpreter ABI Platform Actions
agentdetox-0.5.0-py3-none-any.whl Python 3 none any Details for agentdetox-0.5.0-py3-none-any.whl

Total release size: 679.3 kB

Release files / agentdetox-0.5.0.tar.gz

Download URL agentdetox-0.5.0.tar.gz
Size 426.0 kB
Tags Source
SHA-256 checksum
How to use checksums
8af55f4fbc8774613a78b1b3cfb5fc8e9f3f0855f0830d4b6f5c05704ab28cbc
BLAKE2b-256 checksum
How to use checksums
14ab4ee1f38077413bfbd9192e251a31648a78ba0ffbc6878168fd2061799ca5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

Release files / agentdetox-0.5.0-py3-none-any.whl

Download URL agentdetox-0.5.0-py3-none-any.whl
Size 253.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
563c2eacd214066d4a6a8b31e7ed9bfded42ead0bda76a0017a83d1f43318bd3
BLAKE2b-256 checksum
How to use checksums
a658b2f58486cfbf19c31ae9cdd8393c7da372705bdcadcf5a5e2439f8d913e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

Security for agentdetox 0.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for agentdetox-0.5.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page