/desplega:improve-agents-md runs instead · from desplega
Improves AGENTS.md/CLAUDE.md files using `<important if>` conditional blocks so agents attend to relevant guidance. Useful for bootstrapping, auditing, or tightening project agent instructions.
This skill never runs in Claude Code
It ships in desplega at skills/, but /desplega:improve-agents-md (a command, or a skill Claude Code finds first) has the same name: typing it, or Claude choosing it, runs that one instead.
Progressively improve (or bootstrap from scratch) a project's agent-instruction file. Works on both AGENTS.md (vendor-neutral convention from OpenAI Codex, also read by Cursor, Claude Code, and others) and CLAUDE.md (Claude-specific). Keeps one canonical file on disk and symlinks the other, so every agent reads the same source of truth.
/improve-agents-md (or /improve-claude-md pointed here)Claude Code (and most other agents) inject the project agent-file with a system reminder that says:
"this context may or may not be relevant to your tasks. You should not respond to this context unless it is highly relevant to your task."
So the agent will ignore parts it deems irrelevant. The more content that isn't applicable to the current task, the more likely the agent is to ignore the entire file — including the parts that matter right now. Long, undifferentiated agent files are self-defeating.
Two levers fix this:
<important if="..."> blocks with narrow, specific conditions. This piggybacks on the same XML tag pattern Claude Code uses in its own system prompt, giving the model an explicit relevance signal that cuts through the "may or may not be relevant" framing.The result is a short file where foundational context is always visible and domain guidance only "lights up" when it matches the task at hand.
The skill runs inside Claude Code, so the canonical on-disk file is CLAUDE.md. AGENTS.md exists as a symlink pointing to CLAUDE.md so vendor-neutral agents (Codex, Cursor, Copilot workspace) read the same source of truth.
Resolution logic at the start of every run:
CLAUDE.md and AGENTS.md at the repo root (and in subdirectory if the user invokes from one).CLAUDE.md → operate on it; at the end, offer to create AGENTS.md as a symlink → CLAUDE.md.AGENTS.md (real file, not a symlink) → offer to rename it to CLAUDE.md and create AGENTS.md → CLAUDE.md symlink. If user declines the rename, edit AGENTS.md directly.CLAUDE.md from the codebase, 2. Abort.Always use ls -la (or equivalent) to detect symlinks; never assume from the filename.
This skill is progressive, not one-shot. Use AskUserQuestion at decision points so the user stays in control. The flow below is the default; skip steps if the input file is already clean or the user asks to go faster.
Follow the resolution logic above. State clearly which file you'll be editing and why.
Read the full file. Categorize every top-level section into one of:
| Category | Examples | Treatment |
|---|---|---|
| Foundational (always relevant) | project identity (1 sentence), project map (directory listing), tech stack (1-2 lines) | Leave bare at top. |
| Commands | build/test/lint/dev commands | Wrap in a single <important if="you need to run commands to build, test, lint, or generate code"> block. Keep all commands. |
| Conditional rule | "use Zod for request validation", "API routes go in X" | Wrap in its own <important if> block with a narrow trigger. |
| Domain section | testing setup, state management, i18n, auth | Wrap in one <important if> per section. |
| Lint/formatter territory | camelCase, const over let, strict equality, JSDoc | Delete. Suggest a pre-commit hook instead. |
| Vague exhortation | "follow best practices", "leverage the X agent", "think carefully" | Delete. |
| Stale code snippet | 20-line example of a component | Delete. Replace with a file path reference (see src/utils/example.ts). |
Before rewriting, use AskUserQuestion to confirm the deletions that might be controversial. Don't ask about every cut — only the ones where reasonable people could disagree. Batch them into a single question with a multi-select list:
Example:
"I'd like to drop the following from your CLAUDE.md because they're either linter territory or too vague to act on. Which of these are you OK losing?"
- camelCase / PascalCase rules (linter territory)
- "Write JSDoc for all public functions" (linter can enforce, also stale)
- "Follow clean code principles" (too vague)
- Keep all of them anyway
Skip this step if nothing controversial is being cut.
Show the user the proposed section list with their <important if> conditions — not the full rewrite yet, just the outline. This is cheap and catches disagreements before you do the full rewrite.
Use AskUserQuestion to confirm, with options like:
Before writing anything, copy the current file so you can compute before/after metrics and so the user has a rollback:
cp CLAUDE.md /tmp/CLAUDE.md.before-$(date +%s)
Remember the snapshot path — you'll need it in Step 7.
Write the new file. Show the user a concise diff summary (sections added / removed / reworded). Don't dump the full file into chat — they can read it on disk.
Compute and show a before/after comparison. The four numbers that matter:
| Metric | How to compute |
|---|---|
| Chars | wc -c <file> |
| Lines | wc -l <file> |
| KB | ls -lk <file> (or du -k <file>) |
| Tokens (est.) | chars / 4 — rough English heuristic. Good enough to show direction; don't over-invest in precision. |
Run it for both before (the /tmp/... snapshot) and after (the rewritten file). Present as a compact table:
before after Δ
chars 8,412 3,104 −63%
lines 247 92 −63%
KB 8.2 3.0 −63%
tokens (est.) 2,103 776 −63%
One-shot bash helper (adjust paths):
metrics() {
local f=$1
local chars=$(wc -c < "$f" | tr -d ' ')
local lines=$(wc -l < "$f" | tr -d ' ')
local kb=$(awk "BEGIN {printf \"%.1f\", $chars/1024}")
local tokens=$((chars / 4))
printf "%s\tchars=%s lines=%s kb=%s tokens~%s\n" "$f" "$chars" "$lines" "$kb" "$tokens"
}
metrics /tmp/CLAUDE.md.before-XXXXX
metrics CLAUDE.md
If the after file isn't meaningfully shorter (say, <10% reduction) and the user came in wanting a cleanup, that's a signal you didn't cut aggressively enough — consider a second pass before finalizing. If it got longer, you probably added invented rules; reread your output against the "What Not to Do" list.
Label the after file so the user has a one-word takeaway. Tokens are primary; lines/chars are secondary signals.
| Tokens (est.) | Verdict | What it means |
|---|---|---|
| < 500 | Lean ✓ | Foundational + a few focused <important if> blocks. Target for most projects. |
| 500 – 1,000 | Good | Healthy for mid-sized projects. Still fully attended-to by the model. |
| 1,000 – 2,000 | Fat ⚠ | Almost certainly has linter territory, stale snippets, or grouped rules without narrow triggers. Cut harder. |
| > 2,000 | Bloated ✗ | Most of it will be ignored under "may or may not be relevant". Major rewrite warranted. |
Caveats to apply with judgment, not rigidly:
<important if> triggers is healthier than a 900-token file of bare prose — the model only "spends attention" on blocks whose condition matches.Report the verdict alongside the before/after table so the user sees direction + magnitude + label in one glance.
Offer to create the companion symlink if it doesn't exist:
ln -s CLAUDE.md AGENTS.md # from repo root
Verify with ls -la CLAUDE.md AGENTS.md that the symlink resolves to a real file.
Use AskUserQuestion to offer:
/file-review:file-review)If it's relevant to 90%+ of tasks, leave it as plain markdown at the top. If it's relevant to a specific kind of work, wrap it in <important if>.
Bad — one broad condition swallowing everything:
<important if="you are writing or modifying any code">
- Use absolute imports
- Use functional components
- Use camelCase filenames
</important>
Good — each rule gets its own narrow trigger:
<important if="you are adding or modifying imports">
- Use `@/` absolute imports (see tsconfig.json for path aliases)
- Avoid default exports except in route files
</important>
<important if="you are creating new components">
- Use functional components with explicit prop interfaces
</important>
<important if="you are creating new files or directories">
- Use camelCase for file and directory names
</important>
The whole point of the mechanism is precision. A condition that matches "anytime you write code" is no signal at all.
Do not shard the file into separate referenced docs that require the agent to make extra tool calls to discover — unless the extra content is genuinely verbose (say, >200 lines) and only rarely relevant. <important if> blocks are the progressive-disclosure mechanism; they make everything visible but conditionally weighted.
Frontier models can reliably follow a few hundred instructions; Claude Code's own system prompt and tools already spend ~50 of that budget. Your file should be lean.
Commands are the one section where completeness beats brevity. The agent needs to know what's available even if a command is used rarely. Keep every command from the original; you may drop redundant descriptions, not the command itself.
If a rule isn't self-explanatory, add a short reason. Use prismaMock from packages/db/test is clearer as Use prismaMock from packages/db/test — real DB connections in tests flake on CI. The agent uses the reason to make better judgment calls on edge cases.
Target layout when rewriting. Use this as a skeleton:
# CLAUDE.md
[one-line project identity — what it is, what it's built with]
## Project map
[directory listing with brief descriptions — keep bare]
<important if="you need to run commands to build, test, lint, or generate code">
[commands table — ALL commands from the original]
</important>
<important if="<specific trigger for rule 1>">
[rule 1]
</important>
<important if="<specific trigger for rule 2>">
[rule 2]
</important>
<important if="<specific trigger for domain area 1>">
[guidance for that domain]
</important>
... more sections, each with its own targeted condition ...
Notes:
# CLAUDE.md or # AGENTS.md) should match the canonical file's name.<important if> blocks help rendering in some agents — keep them.When there's no existing file and the user opted into bootstrap:
ls, cat package.json / pyproject.toml / equivalent, identify the primary language and runtime.package.json scripts, or Makefile / justfile / Taskfile targets, or pyproject.toml tool configs. Translate to a commands table.Input (CLAUDE.md before):
# CLAUDE.md
This is an Express API with a React frontend in a Turborepo monorepo.
## Commands
| Command | Description |
|---|---|
| `turbo build` | Build all packages |
| `turbo test` | Run all tests |
| `turbo lint` | Lint all packages |
| `turbo dev` | Start dev server |
| `turbo db:generate` | Generate Prisma client |
| `turbo db:migrate` | Run database migrations |
## Project Structure
- `apps/api/` - Express REST API
- `apps/web/` - React SPA
- `packages/db/` - Prisma schema and client
- `packages/ui/` - Shared component library
## Coding Standards
- Use named exports
- Use functional components with TypeScript interfaces for props
- Use camelCase for variables, PascalCase for components
- Prefer `const` over `let`
- Always use strict equality (`===`)
- Write JSDoc comments for all public functions
## API Development
- All routes go in `apps/api/src/routes/`
- Use Zod for request validation
- Use Prisma for database access
- Error responses follow RFC 7807 format
- Authentication via JWT middleware
## Testing
- Jest + Supertest for API tests
- Vitest + Testing Library for frontend
- Mock database with `prismaMock` from `packages/db/test`
Output (CLAUDE.md after):
# CLAUDE.md
Express API + React frontend in a Turborepo monorepo.
## Project map
- `apps/api/` — Express REST API
- `apps/web/` — React SPA
- `packages/db/` — Prisma schema and client
- `packages/ui/` — Shared component library
<important if="you need to run commands to build, test, lint, or generate code">
Run with `turbo` from the repo root.
| Command | What it does |
|---|---|
| `turbo build` | Build all packages |
| `turbo test` | Run all tests |
| `turbo lint` | Lint all packages |
| `turbo dev` | Start dev server |
| `turbo db:generate` | Regenerate Prisma client after schema changes |
| `turbo db:migrate` | Run database migrations |
</important>
<important if="you are adding or modifying imports or exports">
- Use named exports (no default exports).
</important>
<important if="you are creating new components">
- Functional components with TypeScript interfaces for props.
</important>
<important if="you are adding or modifying API routes">
- Routes live in `apps/api/src/routes/`.
- Use Zod for request validation.
- Use Prisma for database access.
- Error responses follow RFC 7807.
- Auth via JWT middleware — see `apps/api/src/middleware/auth.ts`.
</important>
<important if="you are writing or modifying tests">
- API: Jest + Supertest.
- Frontend: Vitest + Testing Library.
- Mock database with `prismaMock` from `packages/db/test` — real DB in tests flakes on CI.
</important>
What was cut and why:
const vs let, strict equality, JSDoc → linter/formatter territory.<important if> blocks.What was preserved:
<important if>. Specificity is the whole point.node_modules/, dist/, .git/, vendor/ during bootstrap.What SKILL.md sets; muted values are Claude Code's defaults
26 skills in this plugin
/ask-userConventions for asking the user questions during a workflow via the AskUserQuestion tool. Other skills reference this to keep prompts consistent and structured./babysit-prKeep a GitHub PR moving until it is clean on its head commit. Each round fixes CI failures, handles review findings, rebases when needed, re-triggers the reviewers, and then waits in the background for the next event. Use when the user says "babysit the PR", "watch the PR until it's approved", "keep going until approved", "monitor the PR", or invokes /babysit-pr. Merges only when the user asks for it./brainstormingInteractive exploration of ideas through Socratic Q&A. Produces progressive documents that serve as lightweight pre-PRDs feeding into research.npx claudepluginhub desplega-ai/ai-toolbox --plugin desplegaOther plugins' skills for the same job