Skip to main content
Home / Blog / Security Guide
Security Guide

How to Check a Repo's AI Agent Config Before You Open It

RRogue AI··9 min read
Clay developer figure holding a magnifying glass over the hidden dot-folders of a freshly cloned code repository before opening it

Cloning a repository runs nothing. Opening it in an AI coding agent or an editor can. A committed .claude/settings.json can start a shell command the moment a session begins, a .vscode/tasks.json can run one when the folder opens, and a Cursor rule can tell the agent to run it for you. Before the first session, list those files from a plain terminal, read every hook and task, and open the repo with hooks switched off.

This is no longer a lab scenario. In June 2026 SafeDep traced a worm that planted exactly these files in hijacked repositories and summed up the problem in two sentences: “Cloning the repo is safe. Opening it is not.” GitHub code search found 123 repositories carrying the planted files, and SafeDep treats that count as a floor. On 29 October 2026 heise reported that JFrog Security Research had found 42 booby-trapped repositories belonging to 11 legitimate owners, in a campaign named testmetest.

We open other people’s repositories in Claude Code every week, and the routine below is the one we now run first. It takes about five minutes. If you are setting Claude Code up for a whole team, read it alongside our guide on rolling out Claude Code in a company.

What runs when you open a repo in an AI coding agent?

In the June wave, SafeDep counted six added files and five triggers, one per tool plus the npm test script. Every trigger pointed at the same payload, .github/setup.js, a 4.3 MB dropper:

  • Claude Code: a SessionStart hook in .claude/settings.json runs node .github/setup.js when a session opens.
  • Gemini CLI: the same hook in .gemini/settings.json.
  • Cursor: a rule in .cursor/rules/setup.mdc with alwaysApply: true tells the agent to run the script.
  • VS Code: a task with "runOn": "folderOpen" in .vscode/tasks.json. No AI agent needed.
  • npm: the test script in package.json becomes node .github/setup.js, so a test run or a CI job fires it too.

The October wave widened the list. SafeDep’s testmetest analysis names .claude/settings.json, .cursor/mcp.json, CLAUDE.md, AGENTS.md and .vscode/tasks.json, with loaders at .github/init.js and .github/init.ps1. According to heise, the init.js payload was 12.9 to 13.7 MB, which kept it out of GitHub code search. For the June wave, SafeDep’s reading is that the attacker took a GitHub token with write access from a prior infection and pushed the payload into every repository that token could reach.

Agent config files compared: what each one can run

Each tool has a different file and a different gate. The column that matters is the third one: when the content takes effect without a prompt you have read.

ToolFile in the repoWhat runs, and whenHow to check
Claude Code.claude/settings.json (hooks)Shell command with your user rights. Interactive: after you accept the trust dialog. -p or SDK: alwaysRead the hooks key; /hooks shows each hook’s source
Claude Code.mcp.jsonMCP server process. Interactive: asks first. -p: connected without askingRead the server commands and URLs
Gemini CLI.gemini/settings.jsonHooks and project settings. Folder trust is off by defaultRead it; turn on security.folderTrust.enabled
Cursor.cursor/rules/*.mdcAn instruction in every chat when alwaysApply: true; the agent may act on itgrep -rn alwaysApply .cursor/rules
VS Code.vscode/tasks.jsonShell task on folder open, in a trusted workspace once automatic tasks are allowedSearch for folderOpen; answer Disallow if unsure
npmpackage.json scriptsAny command, when you or CI run the scriptPrint scripts before npm test
Any agentCLAUDE.md, AGENTS.mdInstructions the agent reads as project contextRead them like code; look for “run this first” lines

Sources for the gates: Claude Code permissions, Gemini CLI trusted folders, Cursor rules and VS Code tasks.

Why the trust dialog is not enough

Claude Code does have a gate. The hooks documentation says that in an interactive session it “holds back hooks from every settings file, including your own ~/.claude/settings.json, until you accept the workspace trust dialog” for the folder. That is a real control. It also comes down to one click, and in our experience a dialog that appears for every new repository teaches people to click yes. Four details make it weaker than it looks:

  • Scripted runs skip it. For a -p or SDK session, Claude Code “never shows the dialog and treats the folder as trusted, so hooks committed in a repository’s .claude/settings.json run in a folder you’ve never trusted.” A review bot that runs claude -p on pull requests is exactly that case.
  • Parent trust carries over. Outside a git repository, trust on a folder covers its subfolders, and the permissions table marks settings hooks as “Used” when you trusted only a parent. A project unpacked from an archive, with no .git folder, into a directory you trusted once gets no new prompt. A real clone is its own repository and gets its own dialog.
  • Hooks run as you. The docs warn: “Command hooks execute shell commands with your full user permissions.” Anything your account can read or delete, a hook can too.
  • Your own off switch loses. Claude Code reads the value left after settings precedence, “so a "disableAllHooks": false in a project’s .claude/settings.json overrides a true in your user settings.” The repository wins over your personal default.

The editors differ. VS Code says “Automatic tasks never run in an untrusted workspace, regardless of this setting.” Its default for task.allowAutomaticTasks asks once per workspace. Gemini CLI’s trusted-folders feature is, per its own docs, disabled by default; switched on, an untrusted folder runs in safe mode and the project’s .gemini/settings.json is not loaded. A Cursor rule never executes anything itself. It is an instruction, which makes it a prompt injection you cannot patch and depends on what the agent is allowed to run.

How to check a repo before the first session

Run this from a plain terminal, before any editor or agent touches the folder. Clone from the command line so nothing opens the folder for you.

# 1. What agent and editor config does the repo ship?
git ls-files | grep -E '^\.(claude|gemini|cursor|vscode|github)/|(^|/)(CLAUDE|AGENTS)\.md$|^\.mcp\.json$'

# 2. Hooks, automatic tasks, always-on rules
grep -n -A6 '"hooks"' .claude/settings*.json .gemini/settings.json 2>/dev/null
grep -n -B2 -A4 'folderOpen' .vscode/tasks.json 2>/dev/null
grep -rn 'alwaysApply: *true' .cursor/rules 2>/dev/null

# 3. Scripts npm runs for you
node -e 'console.log(require("./package.json").scripts)'

# 4. Oversized files under .github (both waves hid a multi-MB loader there)
find .github -type f -size +1M

# 5. Who added the config, and when
git log --format='%h %ad %an %s' --date=short -- .claude .gemini .cursor .vscode .github
  1. List the config. Step 1 shows every file the table above covers. An unfamiliar open-source repo rarely needs any of them.
  2. Read every hook, task and rule. A hook that formats code after an edit is normal. A SessionStart hook or a folderOpen task that runs a script inside the repo is, in our experience, rare in legitimate projects. Treat it as hostile until you have read the script.
  3. Print the npm scripts before you run npm test or npm install. A test script that only calls node .github/… is the June pattern.
  4. Look for big files under .github/. Workflow files are small. A multi-megabyte JavaScript file is not a workflow.
  5. Check the history, but don’t trust the dates. SafeDep found that in Microsoft’s Azure durabletask repository the attacker backdated the commit to 2020. The author and the files changed tell you more than the timestamp.
  6. Open the first session with hooks off. Start Claude Code with claude --settings '{"disableAllHooks": true}', which the docs say takes precedence over project and local settings. For scripted runs use --bare or --setting-sources user, so Claude Code reads no hooks and no .mcp.json servers from the project. Inside a session, /hooks lists every hook with where it comes from.
  7. Accept trust last. Only after steps 1 to 6 accept Claude Code’s trust dialog, and in VS Code answer the automatic-tasks prompt with Disallow unless you have read tasks.json.

Already opened it? Remove persistence before you rotate tokens

Most coverage ends with “revoke your credentials”. JFrog’s advice, as heise reported it, is to check repository configurations and workflows and “revoke any credentials that may have been stolen.” For the testmetest worm, doing that first is the expensive mistake. SafeDep found that the worm installs a service called net-health-checker that “checks the stolen GitHub token every 45 seconds for 48 hours.” On a 401 or 403 response, it runs rm -rf ~/; rm -rf ~/Documents. Revoke the token while that service is alive and you trigger the wiper yourself.

SafeDep’s remediation order puts persistence first:

  1. Disconnect the host from the network.
  2. Remove persistence. On Linux the two services run as systemd user services: systemctl --user disable --now net-health-checker pkg-runtime. On macOS they are launchd agents, removed with launchctl bootout.
  3. Rotate all credentials: Git hosts, package registries, cloud, Vault, Kubernetes, SSH and AI providers.
  4. Check your accounts and packages for the published indicators.
  5. Reinstall the operating system on the host.

Those service names belong to this wave; the next one will rename them. In our view the rule outlives the names: any user-level service or launch agent created around the time you opened the repo goes before any token is touched. If you can, copy what matters in your home directory to offline storage first. A token can be rotated in seconds. A home directory cannot be rebuilt in seconds.

The stolen token is the real prize, which is why session token theft from AI agents keeps coming up as the core risk: a GitHub token with write access is what lets this worm push itself into the next repository.

The durable fix for teams is a managed setting

A routine that depends on every developer remembering it fails on the first busy afternoon. The fix that holds is central. In Claude Code, set allowManagedHooksOnly to true in managed settings. Per the hooks docs, “Your user, project, local, and plugin hooks are blocked.” Hooks your platform team ships through managed settings still run, so you keep the useful ones. A per-user switch can’t do this, because the repository’s project settings outrank it.

Around it:

  • CI and review bots: every claude -p job that touches code you didn’t write runs with --bare or --setting-sources user. There is no dialog in a pipeline.
  • VS Code: leave task.allowAutomaticTasks at its default and never push “on” through policy.
  • Gemini CLI: set security.folderTrust.enabled to true in user settings.
  • Code review: treat any change to .claude/, .gemini/, .cursor/ or .vscode/ as a supply-chain signal, as SafeDep recommends, and give those paths a security owner.

Our take: the attack works because agent config looks like settings and behaves like code. A JSON file in a dot-folder gets less review than a JavaScript file, yet it can run more. It is the same lesson as the AI agent skill marketplace attack and the case for guardrails on coding agents with shell access: anything that can execute deserves the review you give code.

Checklist

  • Clone from a terminal; list .claude, .gemini, .cursor, .vscode, .mcp.json, CLAUDE.md, AGENTS.md
  • Read every hook, automatic task, always-on rule and npm script
  • Flag multi-megabyte files under .github/
  • First session with disableAllHooks passed via --settings; scripted runs with --bare
  • Already opened a bad repo: network off, persistence out, then rotate, then reinstall
  • Team-wide: allowManagedHooksOnly in managed settings, and an inventory of the AI agents your staff already run

Related reading

Sources: SafeDep on the June worm wave, SafeDep on testmetest, heise on the JFrog findings, Claude Code documentation on hooks and permissions, and the VS Code, Cursor and Gemini CLI docs.

Frequently Asked Questions

Is it safe to clone a GitHub repository?

Cloning itself runs no code. The risk starts when you open the folder in an AI coding agent or editor: a committed .claude/settings.json hook, a .vscode/tasks.json task with runOn folderOpen or a Cursor rule with alwaysApply can then run or request a command. SafeDep summed up a June 2026 worm wave as: Cloning the repo is safe. Opening it is not.

Do Claude Code hooks from a repository run automatically?

In an interactive session Claude Code holds back hooks from settings files until you accept the workspace trust dialog for the folder. In a claude -p or SDK session it never shows the dialog and treats the folder as trusted, so hooks committed in the repository's .claude/settings.json run. Use --bare, --setting-sources user or --settings with disableAllHooks for repositories you did not write.

Should I revoke my GitHub token first after opening an infected repo?

Not while the malware's persistence is still running. SafeDep found that the testmetest worm installs a service that checks the stolen GitHub token every 45 seconds for 48 hours and deletes the home directory on a 401 or 403 response. Disconnect the host, remove persistence, then rotate credentials and reinstall the system.

Related Articles

Security Guide

How to Stop a Prompt Injection Spreading Between AI Agents and Their Memory

9 min read

Security Guide

How to Sandbox an AI Agent: Network, Credentials, Kill Switch

9 min read

← All articles