Agentic repo lint
Periodic cleanup audit of the agent setup around one repo: whatever reaches Claude Code, Codex and Antigravity there. Agents that run for months leave clutter behind; this finds it. It is not a security scanner.
The target layout is references/policy.md. Read it before step 2; every finding is a gap between the repo and that policy, or a line that wastes context.
- Config:
~/.agents/agentic-repo-lint.json(optional) turns the opinionated rules on; without it the defaults in policy.md apply.inventory.configshows what is in effect. - Paths:
${CLAUDE_SKILL_DIR}is this skill's folder (the one holding this SKILL.md). Agents that do not fill it in use that folder's path instead. - Language: write the report and talk to the user in their language, or in the config's
languagewhen it is set.
How to work
This skill is the procedure; the two scripts are instruments. Pick an instrument for the question in front of you, read what it returns as leads, and settle every lead against the intent of its rule in policy.md.
lint.pyanswers "where does this setup drift from the layout?" Open the file behind each lead and decide: a real finding, explained away, or a lint bug to note in the report.usage.pyanswers "is this skill or MCP server still used?" A count is evidence to weigh beside git history and the repo's stack; the verdict is yours.- Intent outranks mechanism. A
CLAUDE.mdthat imports@AGENTS.mdkeeps one source of truth as surely as a symlink does. On Windows, or with an agent the scripts do not know, judge by what the rule protects. Fix commands are written for a POSIX shell; translate them to the user's shell. - The scripts see Claude Code, Codex and Antigravity only. When the repo also serves another agent (
.cursor/,.github/copilot-instructions.md,.windsurf/…), look at its config yourself and say in the report header that the script did not cover it. - What no script can see is yours to judge: whether a skill is still needed, whether an instruction line is stale, whether a server belongs to this repo. Steps 2 and 3 are that work.
Scope: the git root of the current directory, plus the global config it inherits (~/.claude, ~/.claude-*, ~/.agents, ~/.claude.json, ~/.codex, ~/.gemini/config). A path given with the request replaces the current directory.
Never echo a secret. Settings, .claude.json, MCP env blocks and hook commands can hold keys and tokens. When you read or back up these files (steps 3 and 5), quote no secret value, or any part of one, in the report, a command or a commit; write <redacted> in its place. Validate JSON silently (jq empty <file>), never by printing the file. When a key turns up in a place it should not be, say once in the report that it may need rotating if that file ever left the machine.
1. Mechanical check
python3 "${CLAUDE_SKILL_DIR}/scripts/lint.py" --repo <repo> --json --save
- The script reads the repo and the config only. It writes in
~/.agents/lint-runs/<repo>-<hash>/and nowhere else:--savestores the run there and--acceptrecords accepted findings there. On the first such write it moves the runs of an olderlint-runs/<repo>/folder into it. Every run is compared with the last saved one. - Each finding has an
id(short and stable, used by--accept), acode(rule),severity(error,warn,info),where,message,fixandstatus(neworpersisting).resolvedlists findings of the previous run that are gone. acceptedlists findings the user chose to keep, each with itsreason; they stay out offindingsand the counts.inventoryholds what the agents see:- every skill Claude can load, with its description size and
state:listed,name-only,offoruser-only(onlylistedandname-onlycount toward the token estimate); plugin skills appear as<plugin>:<skill>; - the MCP servers of Claude (every account and enabled plugins), Codex and Antigravity, each with
agent,sourceandenabled; - the claude.ai connector and skill-sync switches, and the size of the always-loaded instruction files (rules without
paths:andCLAUDE.local.mdincluded); hooks(commands, redacted),claude_rules,agents,commands,plugins,imports(@pathin instruction files), andcodex(config files, the repo's trust level).
- every skill Claude can load, with its description size and
- Codex's
config.tomlneeds Python 3.11+ (tomllib); an olderpython3reportscodex-configand skips it. - If
lint.pycrashes, show the user the last lines of the traceback and do steps 2-4 by hand from policy.md; propose thelint.pyfix in the report. - After any change to
scripts/lint.py, run its tests first:python3 -m unittest discover -s "${CLAUDE_SKILL_DIR}/tests".
2. Skill cleanup
Every skill an agent can load here gets a verdict: keep, fix, move or delete. The scope covers:
- the root
.agents/skills; - every feature's own
.agents/skills; - folders that
skill-misplacedreports; - the global skills in
inventory.skills.
-
Usage. Start it in the background (it scans every session log, often many GB) and do step 3 meanwhile; wait for its counts before judging any skill:
python3 "${CLAUDE_SKILL_DIR}/scripts/usage.py" --exclude-session "${CLAUDE_SESSION_ID}" --skills a,b,c --mcp x,y--skillsand--mcptake comma-separated names (the skills in scope, the servers ininventory.mcp_servers). Outside Claude Code, drop--exclude-sessionwhen you do not know your session id.- It counts the sessions in which Claude or Codex used each skill or called each MCP server's tools; a subagent's log counts toward its parent session. Its first line names the window: all logs, or the last N days with
--days N. A zero inside a window is not "never used". - Pair each skill count with
git log --follow -- <skill>/SKILL.md. A creator skill can be maintained in git while no agent session reads it, so a low count alone proves nothing.
-
Judge each skill. For a global skill, start from its description, its usage count and its relevance to the repo (item 5). Read the whole SKILL.md only for repo skills and for global skills that may need fix, move or delete; a plainly relevant, used global skill is a keep without reading its body. For each skill you read, judge:
- Works: the inputs, scripts and folders it names exist.
skill-dead-refis the first pass; paths written in prose need your own check. - Still needed: a skill whose outputs exist and whose sources are gone is a finished one-off.
- Quality:
- no-ops ("you are an expert…");
- schemas copied into the skill that have drifted from the real data;
- steps that contradict each other.
- Placement:
- A skill that serves one feature lives in that feature's
.agents/skills. - Repo-wide audits live at the root.
- Third-party skill sets live globally only.
- A skill that serves one feature lives in that feature's
- Works: the inputs, scripts and folders it names exist.
-
Before a delete: check whether the skill holds the only copy of a script that a README, an AGENTS.md or another script runs. If it does, move that script to the feature's
scripts/and repoint the docs, so the delete removes the skill and nothing else. -
Present one skill at a time. A group is fine when its members share a verdict and a reason. Give:
- what it does;
- its last use;
- what works and what is broken;
- your verdict and why.
Then wait for the answer before presenting the next skill. Record the verdict; delete or move nothing yet.
-
Global skills:
- Relevance: learn the repo's stack from its manifests (
pubspec.yaml,package.json,pyproject.toml…) and its top folders. A global skill whose description has nothing to do with that stack is a candidate. Ask instead of guessing when a skill could plausibly be used here. - Removal changes every repo. Offer
skillOverrides"off"for this repo as the alternative.
- Relevance: learn the repo's stack from its manifests (
Done when every skill in scope has a verdict the user accepted. The verdicts are applied in step 5, with the other approved fixes.
3. Judgement review
The script cannot judge relevance or wording. Do these yourself, reading the files:
- Instruction files.
- Read: the repo's root
AGENTS.mdand every nested one,~/.claude/CLAUDE.md,~/.codex/AGENTS.md, and the project'sMEMORY.mdwith each memory file. - Flag a line when it is:
- a no-op: something the model does by default;
- a cache: it restates
pubspec.yaml,package.jsonor the directory layout; - sediment: stale facts, or tools and paths that are gone;
- duplication: the same rule in two files;
- a contradiction: it conflicts with another file, or with a memory.
- Pointers bound to one machine or account (for example
~/.claude-work/...) are findings too.
- Read: the repo's root
- MCP relevance. An enabled server in
inventory.mcp_serversthat the repo never needs, or thatusage.py --mcpshows unused, is a finding, for every agent.mcp-duplicateshows every place to clean in one go. - Hooks. Look over
inventory.hooksfor leftovers: a hook for a tool that is gone, or one nobody recognises. Ask the user about those; this is cleanup, not a security audit. - Script findings. Confirm each one before reporting it;
infofindings may be dropped when they carry nothing actionable. A false positive is a lint bug: note it in the report and propose thelint.pyfix.
Done when every instruction file, MCP server and hook has been looked at, and each script finding is confirmed or explained away.
4. Report
Skill verdicts were settled one by one in step 2. List them once under their own heading (skill, verdict, action), so step 5 applies them with the rest; the numbered findings cover everything else.
- Header, one line: repo, remote, skills listed to Claude with their estimated tokens, MCP servers, and whether connectors and skill sync are on or off.
- Findings: numbered
A-1,A-2…, errors first.- Each one gives where, what, why it matters, and the proposed fix.
- Mark each 🆕 (new) or ↺ (persisting). List
resolvedfindings at the end as ✅.
- Grouping: findings with one shared fix (for example ten stale permission rules) become one item.
- Ending: close by asking which items to apply, for example "all", "A-1, A-3" or "all but A-2".
5. Fixes, after approval only
-
Apply exactly the approved items, including the skill verdicts from step 2.
-
Kept on purpose: when the user decides to keep a finding as it is, record it by the
idthe script prints, so later runs stop raising it:python3 "${CLAUDE_SKILL_DIR}/scripts/lint.py" --repo <repo> --accept <id> --reason '<the user's reason>'. One--accepttakes one finding. For a group, run it once per id;--accept-prefix '<code>|<where>'takes every match and prints them, so use it only when the user approved the whole group. -
Skill deletes and moves:
- Before deleting a skill folder that git does not track, copy it to
~/.agents-backup/skills/<stamp>/. - A skill listed in
~/.agents/.skill-lock.jsonwas installed by the skills CLI: remove it withnpx skills remove -g <name>, never by hand. - Otherwise delete the folder and its link in
~/.claude/skills(and in each~/.claude-*/skillsthat is a real folder). - Afterwards clear the references to it from READMEs, AGENTS.md and
.codex/rules.
- Before deleting a skill folder that git does not track, copy it to
-
Before overwriting a file, look at its current content.
-
Before rewriting a settings file, back it up to
~/.agents-backup/settings/<stamp>/(mkdir -pit, thenchmod 700 ~/.agents-backup; not/tmp, settings can hold secrets). Keep JSON valid: check it withjq empty <file>, orpython3 -m json.tool <file> >/dev/nullwhenjqis missing; never print the file. -
Protected paths: the sandbox blocks writes to
.claude/settings*.json,.claude/skills,~/.claude/skillsand~/.claude/settings.json. Retry those writes outside the sandbox, which goes through a permission prompt. -
autoMode: the classifier refuses edits to theautoModeblock. Back the file up first (see the settings bullet above), then give the user one exact line to run, built on this template (BSDsed -idiffers from GNU, and regex edits break JSON). Set the path to the account the finding names (~/.claude/settings.json,~/.claude-<name>/settings.json) and replaceEDITwith the change, e.g.d["autoMode"]["environment"].remove("…"):! python3 -c 'import json,os,tempfile; p=os.path.expanduser("~/.claude/settings.json"); d=json.load(open(p)); EDIT; f=tempfile.NamedTemporaryFile("w",dir=os.path.dirname(p),delete=False); json.dump(d,f,indent=2,ensure_ascii=False); f.write("\n"); f.close(); os.replace(f.name,p)' -
Repo changes: stage them and offer a commit holding only these files. Any unrelated work in the tree stays out of it.
-
Re-run step 1 with
--save, so the next audit starts from the fixed state. Report what changed.