All writing

Letting a repository extend a global coding-agent skill without forking it

I keep my coding-agent skills (the Markdown procedures Claude Code and Codex load on demand) in one personal repository, and an install script links them into ~/.claude/skills/ and ~/.agents/skills/ so every project gets the same ones. That works well until one project needs the same procedure with its own commands in it, and this post is about why a copy of the skill is the wrong answer to that, and what we can do instead.

How the copy got there

The skill in question checks that new tests can fail, by breaking the production line a test is supposed to observe, running the test, and restoring the line. The general procedure is the same everywhere, but in an iOS app I’m working on, every step has project-specific bits in it (the scoped test command, the script that finds a test’s type name, where result bundles go, the log lines that mean “this run proves nothing”). So the app repository got its own copy at .claude/skills/mutation-check/SKILL.md, 346 lines of it, and the global copy got a paragraph at the top saying, roughly, if the repository has its own copy, read it and follow that one instead.

The two copies drifted, of course, and I had just re-synced the global one to the app’s copy by hand (a couple of hundred lines changed) when I started looking for a way out. The first thing most of us would reach for is an “expansion” file in the repository that takes highest priority over the shared skill, which was my first idea too.

Before writing that down, it’s worth checking how Claude Code picks between two skills with the same name, and the skills docs are clear about it in § “Resolve skills that share a name”:

Enterprise over personal, and personal over project.

So the project copy never ran as a skill at all. The session’s skill list showed one mutation-check with the global copy’s description, and the only reason the app’s version ever got used was that the global copy told the agent to go open the other file. That deferral paragraph was the whole mechanism, and it’s also why the drift was invisible, since nothing ever compared the two.

Slots instead of a copy

A free-form expansion has the same problem as the copy, only smaller, which is that nothing says where it starts and stops applying, and it can relax a safety rule as easily as it adds a command. What works better is closer to a template. The global skill marks each place a repository may supply its own lines, around only those lines:

<!-- slot: scoped-run-command -->
```bash
<scoped test command> > <check-dir>/mutant-1.log 2>&1
echo "EXIT=$?" >> <check-dir>/mutant-1.log
```
<!-- /slot: scoped-run-command -->

The text between the markers is the default, and everything around it stays fixed. The repository writes only its differences, in .agents/skill-extensions/mutation-check.md, one section per slot:

---
extends: mutation-check
---

## slot: test-identifier

```bash
./scripts/find-tests.sh <keyword>
```

The file sits next to .agents/skills/ rather than inside it, so Codex doesn’t pick it up as a skill, and Claude Code, which documents only .claude/skills/ for project skills, doesn’t either. The skill declares eleven slots in a table (id, kind, which step, one line on what it holds), and a slot is either replace (the extension’s text stands in for the default) or append (both apply, for lists a repository only adds to).

Bounding each slot by the next heading looks like less typing (it’s what my first version did), but a review pointed out that the rules for reading a result (“Kill”, “Survival”, “No verdict”) are bold paragraphs inside one step, not headings. A heading-bounded slot around the runner’s output would have swallowed all of them, and a repository replacing that slot would have replaced the rules too. Explicit close markers fix that, and they also let general rules like “never pipe a test run to tail” sit right next to a slot without being inside it.

The rules no repository may weaken get their own anchors (<!-- invariant: no-git-restore -->), and the skill repo’s checker fails if an invariant anchor ends up inside a slot’s markers. There are seventeen of those for this skill (start from a green run, one production statement per mutant, never git restore a probe, a kill has to name the test, and so on), and the skill states a short precedence order, where an invariant always holds, a slot’s text is the procedure between its markers, and an ## Additional rules section can only add steps, never replace or reorder them.

Loading it with a script

The skill’s step 0 tells the agent to run a loader script bundled with the skill and quote its outcome line in its first message:

cd <checkout under check> && "${CLAUDE_SKILL_DIR}/scripts/load-extension.sh"

In Codex, where ${CLAUDE_SKILL_DIR} isn’t replaced, it runs the same script from ~/.agents/skills/mutation-check/scripts/. The loader reads the skill’s own SKILL.md for the declared slots, so it never needs updating when slots change, and it prints one of eight outcomes, each with its own exit status:

OutcomeExitAgent does
LOADED <path>0Follows the skill with the extension applied.
NO-EXTENSION root=<root>0Follows the skill alone.
NOT-IN-REPOSITORY cwd=<cwd>0Follows the skill alone, and says so.
LOADER-ERROR <detail>2Stops. Never reads it as “no extension”.
UNTRUSTED root=<root> <path>3Follows the skill alone, never the file.
REPOSITORY-COPY <path>4An old branch still has the fork, so it follows that.
CONFLICT <copy> <extension>5Stops, since there are two authorities.
REFUSED <reason> <path>6Stops, with the reason.

REFUSED includes a symlink, a file outside the repository root, anything over 64 KiB, a wrong extends:, duplicate or empty slots, and a heading that names a slot the skill doesn’t declare. That last one replaced a revision number the extension was going to be pinned to, because a renamed or removed slot already shows up as unknown-slot:<id>, and so does an extension written for a newer skill than the one installed. A slot whose meaning changes without a rename isn’t caught by anything, so the rule there is to rename it.

Claude Code also has render-time injection, where a skill runs a command while it renders and inlines the output, which would make loading a guarantee instead of a step. I’ve left that for later, because approving the command through the skill’s allowed-tools grants it for the whole turn the skill is invoked in, the agent’s own calls included, an unapproved command aborts the skill outside auto mode (and so does one that exits non-zero), and I don’t know yet whether Codex supports anything like it. For now, one ordinary tool call under the session’s normal permissions is the smaller thing to trust.

Trusting the repository

Once repository text can change what an agent runs, loading it is a trust boundary like any other untrusted input. Anyone who clones a repo with a .agents/skill-extensions/mutation-check.md in it would otherwise get to put commands in front of your agent, and a line in the shared instructions telling the agent to be careful enforces nothing. So the loader only reads extensions from repositories listed in a trusted-repositories file in the user’s config directory, which we edit by hand and nothing writes for us, keyed on the git common directory:

git rev-parse --path-format=absolute --git-common-dir

Every worktree of a checkout prints the same path for that, and no ordinary clone does, which a remote URL can’t give us since every clone has the same remote. Trust is per checkout, not per content, so whatever branch is checked out in a trusted repository gets loaded, a contributor’s branch included.

The first version of the loader had two holes, both fixed now. It decided on a same-name repository copy (the old fork) before it looked at the allowlist, so any untrusted repo shipping .claude/skills/mutation-check/ would have been followed, and the fix was to check trust whenever there is anything at all to follow. And an untrusted tree could point its own .git file or commondir at a trusted repository’s .git and pass the check, so now the root also has to appear in git --git-dir=<common dir> worktree list, since a tree can point itself at a repository but can’t add itself to that repository’s worktree list.

Codex, run under codex exec -s read-only, could run the loader too, which I wasn’t sure of going in.

What changed

The app’s 346-line fork became an extension that fills eleven slots, and the general procedure now exists once, in the shared skill. If you share skills across projects, the thing to know is that a personal skill wins over a same-name project skill in Claude Code, so a project override only runs because something tells the agent to read it, and nothing keeps the two in sync. Named slots with explicit close markers, fixed rules anchored outside them, and a small loader that prints exactly what it did keep one procedure, and that loader should check that the repository is one you trust before it reads anything from it, since its text ends up in the agent’s instructions.

Email address copied [email protected]