When you set up a local AI coding agent, you usually watch your prompts and rule files like CLAUDE.md or AGENTS.md to make sure nobody sneaks in an injection and tricks the model into doing something foolish. Right next to them sit .claude/settings.json, .mcp.json, and .vscode/tasks.json. Instructions only try to persuade the model, while configuration files run system commands directly with your full user permissions. Nobody needs to sweet-talk the AI at all.
How Configs and Packages Turn Into a Backdoor
Claude Code, Cursor, Codex, and Gemini CLI edit files, run terminal commands, talk to MCP servers, and trigger startup scripts. By late 2026, real-world attacks shifted straight into this config and dependency layer.
In a Google Threat Intelligence Group report, Mandiant analysts documented multi-agent frameworks like exploit_agent, CAIRN, and PentAGI that shrink the time needed to exploit known flaws from days to minutes. For everyday developers, another case is even more dangerous: North Korean threat groups moved from fake recruiter profiles to modifying .claude/settings.json inside repositories. Drop a hook in there, and the moment you launch Claude Code normally, the agent silently downloads a backdoor in the background. Nobody hacked the model; it just followed the config.
Diagram of a multi-agent framework for offensive cyberattacks from the Google Threat Intelligence Group report (Source: cloud.google.com)
There is a nasty trap here with remembered trust. Once a project folder is marked as trusted (verified on Claude Code 2.1.330), any new hook pulled down via git pull fires automatically on the next launch without asking again. In headless mode (claude -p) or through the Agent SDK, the trust prompt never appears at all: project hooks and MCP servers start immediately.
The second wave hit through dependencies. In November 2026, Microsoft's agent-framework package on PyPI (1.26.1 and 1.26.2) was compromised. Hidden inside was a .pth file, a Python helper script in site-packages that runs on every Python startup before your code even loads. It quietly harvested Azure, AWS, GitHub Actions, Azure DevOps, and LLM API keys and sent them to webhook.site. If your agent updates packages without a lockfile, it can pull a poisoned release on its own.
Late October 2026 hit Cursor too. An API key issued to Cursor leaked at provider Fireworks AI. Attackers accessed old user traces without Privacy Mode enabled (fewer than 0.01% of customers had live keys exposed there), pivoted into internal SaaS tools, and on October 29 swapped the Cursor marketplace cache with trojanized Claude Code extensions 2.1.312 and 2.1.313. The fake build stayed live for about 11 hours, potentially affecting up to 5,000 developers.
Silent Leaks in settings.local.json and the Hunt for Stolen Tokens
Attackers don't even need to poison packages when developers leak keys themselves. An agent asks to run a database command with a password in the arguments, and you reflexively click "Yes, and don't ask again." Claude Code saves that exact command in plain text inside the allow list in .claude/settings.local.json. If you initialize Git later, copy the folder to another machine, or run git add -f, that file lands straight in Git.
In November 2026, an Apiiro scan checked 104,185 public copies of .claude/settings.local.json on GitHub and found 1,122 files holding live secrets (1,379 keys, or 2,539 when counting commit history, shared configs, and transcripts—including PostgreSQL/Supabase passwords, AWS keys, and GitHub, GitLab, npm, and root SSH tokens). Standard scanners like Gitleaks and TruffleHog missed many of them because the passwords sat inside inline bash command strings. Anthropic's head of Claude Code, Boris Cherny, confirmed that settings.local.json should never be committed to Git and said the team is adding built-in secret scanning.
Another goldmine for leaks is local chat history stored in JSONL (~/.claude/projects/ for Claude Code, ~/.codex/sessions/ for Codex). Paste a token into chat once, and it stays on disk in plain text.
The main prize is LLMjacking—stealing API keys and cloud roles (Anthropic, OpenAI, Amazon Bedrock, OpenRouter) to run free queries at someone else's expense. According to GTIG, Mandiant, and Amazon Bedrock cases, abuse can top $100,000 in a single day and reach $1,000,000 before the account gets blocked. Cloud honeypots spot bots scanning GitHub and open gateways nonstop for LiteLLM using the default sk-1234 key, Ollama exposed on 0.0.0.0:11434 without auth, and unauthenticated Open WebUI instances.
LLMjacking activity chart from the Google Threat Intelligence Group report (Source: cloud.google.com)
Five-Minute Baseline Environment Lockdown
You can close most of these holes without buying enterprise security tools. Start with safe launch flags in unfamiliar repos and check Git after every git pull.
# Open a project without hooks (macOS/Linux) or without project configs
claude --settings '{"disableAllHooks": true}'
claude --setting-sources user
claude -p --bare "Inspect the project structure"
# Confirm settings.local.json is not tracked by Git (should output nothing)
git ls-files | grep settings.local.json
# If already tracked: rotate keys first, then untrack the file
git rm --cached .claude/settings.local.json
echo '**/.claude/settings.local.json' >> .gitignore
git add .gitignore && git commit -m "chore: ignore local settings"
Putting disableAllHooks in your user config isn't enough because a project config can flip it back to false. On Windows PowerShell, save {"disableAllHooks": true} to no-hooks.json and run claude --settings no-hooks.json. Inside a session, inspect /hooks, /mcp, and /skills (see the settings docs), and turn on /sandbox on macOS, Linux, and WSL2 (native Windows doesn't support it yet). In VS Code, Cursor, and Windsurf, set "security.workspace.trust.enabled": true and "task.allowAutomaticTasks": "off". In team repos, add /.claude/, /.mcp.json, /.codex/, /.cursor/, /.vscode/, /AGENTS.md, and /CLAUDE.md to CODEOWNERS.
To blunt LLMjacking, put strict spending caps on every individual API key: Anthropic, OpenAI, and OpenRouter let you set limits like $50 per token plus billing alerts. Against poisoned packages, stick to lockfiles (npm ci, pnpm install --frozen-lockfile, uv sync --locked) and release-age delays (minimumReleaseAge: 10080 in pnpm for 7 days, exclude-newer in uv, --before in npm).
Automated Auditing and a Hook That Hides Secrets from the Model
To avoid checking dozens of folders, JSONL logs, and .pth files by hand, grab the free agent-config-audit skill from coleam00/skills. Written in pure Python 3.11+ with zero dependencies and strict read-only access, it checks seven areas: auto-run configs, poisoned packages and .pth scripts, secrets in settings.local.json, Claude Code and Codex histories, fake extensions, LLMjacking gateways, and hidden zero-width characters in CLAUDE.md / AGENTS.md. Always audit an untrusted repo from a session outside that folder so startup hooks don't fire first.
# Audit a single repo and its chat history
python ~/.claude/skills/agent-config-audit/scripts/\
agent_config_audit.py /path/to/repo --history-for /path/to/repo
# Full scan of your workspace, configs, extensions, and chats
python ~/.claude/skills/agent-config-audit/scripts/\
agent_config_audit.py ~/code --user --history
Inside Claude Code, run /agent-config-audit /path/to/repo (or add --json for CI). The scanner masks secret values so they never enter the model's context and flags risky entries with !! (pipe-to-shell, local-settings-tracked, secret-in-history, known-compromised, suspicious-pth).
Your final line of defense is blocking the agent from reading .env and key files. Add a deny list to ~/.claude/settings.json and wire up a PreToolUse hook (see the hooks docs) by copying references/secrets-guard-hook.py to .claude/hooks/secrets.py.
{
"permissions": {
"deny": [
"Read(./.env)", "Read(./.env.*)",
"Read(./secrets/**)", "Read(~/.ssh/**)", "Read(~/.aws/**)"
],
"disableBypassPermissionsMode": "disable"
},
"hooks": {
"PreToolUse": [{
"matcher": "Read|Edit|MultiEdit|Write|Bash|PowerShell|Grep|Glob",
"hooks": [{
"type": "command",
"command": "uv run ${CLAUDE_PROJECT_DIR}/.claude/hooks/secrets.py",
"timeout": 15
}]
}]
}
}
The deny rules block direct file reads, while the hook also catches shell commands (printenv, env, echo $...KEY, os.environ, process.env, rm -rf) while still allowing access to a safe .env.example template.
# Pattern for files and folders blocked from agent access
SECRET_PATH = re.compile(
r"\.env\b|\.pem$|\.key$|id_rsa|id_ed25519"
r"|\.ssh/|\.aws/credentials|\.netrc|credentials\.json",
re.IGNORECASE,
)
# Exit code 2 blocks the tool call and returns the reason to the agent
if is_secret_access(tool_name, tool_input):
print(
"BLOCKED: access to secrets is not allowed.\n"
"Read a committed .env.example template instead.",
file=sys.stderr,
)
sys.exit(2)
Test the setup in one minute by asking the agent to open .env. The hook returns BLOCKED with exit code 2, nudging the model to read .env.example instead. Know its limits too: mentioning @.env directly in a prompt bypasses tool calls and skips the hook; the script also fails open (exit 0 on error) and won't stop an agent from writing a helper script to read the environment in a second step.
Deleting the repo or scrubbing Git history is too late. Treat the machine as compromised and rotate every cloud, repository, and LLM provider key from a separate, clean device.


