Find and redact secrets in AI coding agent histories (Claude Code, and more).
Project description
AgentSweep
Find and redact secrets (API keys, tokens, private keys, DB URLs) that got pasted into your AI coding agent's local history. Runs fully offline — your files never leave your machine.
Status: alpha. Works on Claude Code and OpenAI Codex today. Aider, Cursor, Continue via contributed Source adapters — see CONTRIBUTING.md.
The problem
Claude Code (and every other AI coding CLI) stores your full conversation history as plain-text JSONL on disk — under ~/.claude/projects/ for Claude Code, ~/.codex/sessions/ for OpenAI Codex. Anything you paste — an AWS key, a .env file, a database URL — sits in clear text indefinitely. A typical dev's history accumulates dozens of secrets over months, often without them realizing.
agentsweep scans that history, tells you what leaked, and can redact the secret values in place while preserving the JSONL structure byte-for-byte. It also tells you which keys to rotate, with the right revocation URL for each provider.
Scope of protection: agentsweep itself is fully local and offline — it reads and writes only files on your machine and makes zero network calls. It removes one attack vector: secrets sitting in local history files. It does not affect what your AI provider already received: when you paste a key into Claude Code, Cursor, or any cloud-backed agent, that key already transited the provider's servers before it hit disk. If that concerns you, consider a locally-hosted model (Ollama, LM Studio, OpenCode) where nothing leaves your machine at all — agentsweep pairs especially well with local-model setups.
Why this matters right now
Supply chain attacks are accelerating. In 2024–2025 a wave of malicious npm and PyPI packages — sha256-universal, shailulid, hundreds of typosquats — were caught doing one thing: exfiltrating developer credentials off the machine that installed them. They target environment variables, .env files, shell history, SSH keys, and now AI agent history files.
AI coding assistants have created a new category of credential exposure that didn't exist two years ago:
- You paste a production API key into Claude Code to debug something → it's now in
~/.claude/projects/*/conversations/*.jsonlforever - A compromised npm package runs
postinstall→ scans common paths → finds your JSONL history → exfiltrates 50 API keys in one request - You rotate the key you used in public but forget the dozen others in your history
- Meanwhile your history grows: every
.envyou asked an AI to help with, every DB URL you shared for debugging, every token you pasted for a one-liner
AI agent history is the new .bash_history — except it contains full context, not just commands. The attack tooling already knows this. agentsweep exists to clean up before it's exploited.
Install
Recommended — isolated, no venv conflicts, always works:
uv tool install agentsweep # one-time install; adds `agentsweep` + `asweep` to PATH
uv tool upgrade agentsweep # update to latest
Run without installing (always latest, no cache issues):
uvx agentsweep@latest
uvx asweep@latest
Classic pip:
pip install agentsweep
uvis a fast Python package manager — install it withpip install uvor from astral.sh/uv.uv tool installputs the command in its own isolated environment so it never conflicts with project venvs.
Requires Python 3.11+.
Usage
Interactive mode
Run with no arguments in a terminal and you get the full experience — banner,
numbered menu, typed confirmations before anything destructive, and one-key
undo (restores the .bak backups). Any interactive scan that finds secrets
ends with an offer to redact them on the spot (type REDACT to confirm):
agentsweep
Scripting is unaffected: any flag, or a piped/redirected stream, skips the menu entirely and behaves exactly as documented below.
Flags
Scan (read-only, safe):
agentsweep --source claude-code
agentsweep --source codex
Redact in place (creates .bak backups):
agentsweep --fix --allow-production
Point at an arbitrary folder (e.g. a copy of your history):
agentsweep --root /path/to/jsonl-files --fix
Machine-readable output:
agentsweep --json
Corruption-prevention guarantees
A redactor that corrupts your history is strictly worse than the leak it's fixing. agentsweep enforces these invariants on every --fix:
- Redaction happens in parsed JSON, not on raw bytes. Secrets are replaced as string values inside the parsed structure, then re-serialized. Structural damage is impossible by construction.
- Atomic writes. Every rewrite goes: temp file →
fsync()→os.replace()over the original. A crash at any instant leaves either the complete old file or the complete new file — never a torn write. - Post-write validation. Before committing, every non-empty line in the new content must parse as JSON, and the line count must match the original. If either check fails, the write aborts and the original is untouched.
.bakbackup by default. Refuses to run if a.bakalready exists (so prior backups can't be clobbered).- Path containment. Refuses any target that doesn't resolve inside the source's root.
- Symlink rejection. Refuses symlinks outright.
- mtime window. Refuses files modified in the last 60 seconds (likely an active session).
--forceoverrides. - Running-process check. Refuses if a Claude Code process appears to be running.
--forceoverrides. - Alpha-stage production gate.
--fixagainst the default~/.claude/projects/root requires--allow-productionuntil v1.0. - Audit log. Every write appends SHA256 before/after and path to
~/.claude/agentsweep-audit.jsonl.
Recovery
Every redacted file has a sibling *.bak with the original bytes. To undo:
mv session.jsonl.bak session.jsonl
What's detected
189 high-confidence patterns plus a checksum-validated crypto seed-phrase detector — BIP-39 mnemonics (12/15/18/21/24 words; the wallet format behind BTC, ETH, SOL, BNB, ADA, DOGE, LTC, DOT, AVAX and virtually every major chain) and Electrum seeds are confirmed cryptographically (BIP-39 checksum / Electrum version tag), so English prose that happens to use wallet words never false-positives.
The patterns: AWS access keys, GitHub tokens (PAT/OAuth/App/fine-grained), Stripe live/test, OpenAI, Anthropic, Google API, Slack bot/user/webhook, Hugging Face, JWT, PEM private keys, DB URLs with embedded passwords, npm/PyPI/SendGrid/Twilio tokens — plus 167 rules ported from the gitleaks pack covering GitLab, Grafana, HashiCorp Vault/Terraform, DigitalOcean, Shopify, PlanetScale, Databricks, Atlassian, Azure AD, 1Password, Sentry, New Relic, Mailgun, Datadog, Twilio, Twitter/X, Twitch, Yandex, JFrog, Snyk, Mailchimp, curl credentials on the command line, and many more. Patterns are high-precision — false positives are rare, and provider-context rules are keyword-gated so large pastes stay fast.
What's NOT detected
- Custom/proprietary secrets without a recognizable prefix.
- Monero seed phrases (25 words from Monero's own wordlist — planned).
- Unknown tokens that look like arbitrary base64.
- Secrets split across multiple messages.
- Anything inside a binary/non-UTF-8 file.
For deeper detection, run gitleaks or trufflehog alongside agentsweep — their rule packs are more exhaustive. agentsweep's value is the agent-history-specific surface, not the detection engine.
FAQ
Why does uvx agentsweep show an old version?
uvx caches tools locally. Use uvx agentsweep@latest to always run the newest version (recommended), or force a cache refresh with uvx --reinstall agentsweep.
Where is OpenCode in the menu?
OpenCode support was added in v0.1.1. Run pip install --upgrade agentsweep or uvx agentsweep@latest to get it.
Does agentsweep send my data anywhere? No. It is fully offline — zero network calls during scanning or redacting. The only optional network call is the background update check, which only fetches the latest version number from PyPI.
License
MIT. See LICENSE.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agentsweep-0.1.4.tar.gz.
File metadata
- Download URL: agentsweep-0.1.4.tar.gz
- Upload date:
- Size: 93.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a5ad784b86551cec9b440080a3155fdfd5f8b3ee810e1c00804e0e1b98bb9240
|
|
| MD5 |
e3d8b06bf6bcc0a80b1bed939ef0c1b9
|
|
| BLAKE2b-256 |
1e3399ae7705b29aaf8003ee53760f478467609f89bacdb706de9580e037262e
|
Provenance
The following attestation bundles were made for agentsweep-0.1.4.tar.gz:
Publisher:
release.yml on Ishannaik/agent-sweep
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agentsweep-0.1.4.tar.gz -
Subject digest:
a5ad784b86551cec9b440080a3155fdfd5f8b3ee810e1c00804e0e1b98bb9240 - Sigstore transparency entry: 1798197416
- Sigstore integration time:
-
Permalink:
Ishannaik/agent-sweep@591ef33d7d950e45df53b61face6c38d3ae3cc83 -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/Ishannaik
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@591ef33d7d950e45df53b61face6c38d3ae3cc83 -
Trigger Event:
push
-
Statement type:
File details
Details for the file agentsweep-0.1.4-py3-none-any.whl.
File metadata
- Download URL: agentsweep-0.1.4-py3-none-any.whl
- Upload date:
- Size: 74.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5fc01a28119f4ca497e26fc1c0b65f73f1b46b234d356d23a7a0a13e46470107
|
|
| MD5 |
c256817f7ccbe0f8ca422069b1ca7666
|
|
| BLAKE2b-256 |
b4470cfe0fe945ed0ca9302222dda9c47b0c834a77d96f5cdef4bd933bc77152
|
Provenance
The following attestation bundles were made for agentsweep-0.1.4-py3-none-any.whl:
Publisher:
release.yml on Ishannaik/agent-sweep
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agentsweep-0.1.4-py3-none-any.whl -
Subject digest:
5fc01a28119f4ca497e26fc1c0b65f73f1b46b234d356d23a7a0a13e46470107 - Sigstore transparency entry: 1798197873
- Sigstore integration time:
-
Permalink:
Ishannaik/agent-sweep@591ef33d7d950e45df53b61face6c38d3ae3cc83 -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/Ishannaik
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@591ef33d7d950e45df53b61face6c38d3ae3cc83 -
Trigger Event:
push
-
Statement type: