agentleFS
donmikdonmik/agent-toolkit/skills/prompt-crafter/SKILL.md

prompt-crafter

Skill1 starsChanged 3 months agoUnlicenseView on GitHub

Craft effective prompts for AI coding tasks by applying research-backed principles that prevent cargo-cult copying, reduce hallucination, and improve code quality. Use when writing prompts for subagents, planning tasks for AI coding tools, or structuring instructions that reference existing code as exemplars.

The file

Show its rules and text

We split this skill into the rules it gives an agent

13 rules. About 0 are common, 11 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈11

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use delegation-coach first when:

    line 17
  2. Very specific:

    If these are not available, ask for them or recommend using delegation-coach first.

    line 36
  3. Distinctive:

    When you tell an AI coding agent "follow the existing pattern," it copies EVERYTHING — including the wrong things.

    line 62
  4. Distinctive:

    The #1 intervention: Remove decorative patterns from the code the model will read before worrying about prompt wording.

    line 74
  5. Distinctive:

    Import statements for utilities the new task doesn't need

    line 86
  6. Distinctive:

    Instead of inoculation, clean the exemplar: If you can't clean it, use targeted reference instructions (Principle 2) rather than negative …

    line 128
  7. Distinctive:

    Implication: If your codebase conventions live in decorators, they are maximally cargo-prone.

    line 192
  8. Distinctive:

    When the pattern is semantically rich (retry logic, not a decorator), models sometimes produce conscious rejections — explicit comments …

    line 204
  9. Distinctive:

    Implication: If your prompt asks the model to "follow patterns" and the output has no commentary about pattern choices, the model may be …

    line 216
  10. Distinctive:

    When you can't clean the exemplar, provide a pre-built skeleton for the target file.

    line 222
  11. Distinctive:

    If the model was already clean, the review is redundant.

    line 262
  12. Distinctive:

    Implication: Before investing time in prompt engineering, first decide:

    line 299
  13. Distinctive:

    When reviewing a prompt before sending it to an AI coding agent:

    line 407

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Prompt Crafter

Description

Craft effective prompts for AI coding tasks using principles derived from cargo-cult coding experiments. These experiments tested how AI models copy patterns from exemplar files and identified what makes prompts safe or dangerous.

The core finding: your exemplar files are a steering input, and model choice affects how cleanly the model responds to that steering. Later Musa experiments showed that stronger models still help, but they do not make exemplar steering disappear on medium, architecture-sensitive tasks.

Recommended workflow

Use delegation-coach first when:

  • task type is unclear
  • workflow choice is unclear
  • exemplar risk is unclear
  • you are not sure whether to scaffold or review
  • you are deciding between productive work and experiment mode

Then use prompt-crafter to turn that framing into an execution-ready prompt.

Best inputs for this skill

prompt-crafter works best when given:

  • task class
  • target workflow
  • exemplar guidance
  • constraints
  • validation command
  • review lens

If these are not available, ask for them or recommend using delegation-coach first.

Scope boundary

This skill is for:

  • writing prompts
  • auditing prompts
  • turning a known task framing into an execution-ready instruction set

This skill is not primarily for:

  • deciding whether the task is ready to delegate
  • deciding whether the baseline is clean
  • classifying the task from scratch

That is delegation-coach territory.

Quick Start

/skill:prompt-crafter                          # Interactive: discuss what you need
/skill:prompt-crafter --task "implement X"     # Generate a prompt for a specific task
/skill:prompt-crafter --audit                  # Audit an existing prompt for risk factors

Problem This Solves

When you tell an AI coding agent "follow the existing pattern," it copies EVERYTHING — including the wrong things. Decorators with wrong names, abstractions that don't fit, legacy quirks. This skill helps you write prompts that get the right behavior.

The Thirteen Principles

These come from experimental research (see cargo-cult-findings.md in this skill directory). Experiments 3–13 tested decorator cargo (surface syntax), semantic cargo (architectural patterns), defense strategies, and their interaction with prompt variants across multiple models.

1. Clean Your Exemplars First

The #1 intervention. Remove decorative patterns from the code the model will read before worrying about prompt wording.

Risk LevelExemplar StateExpected Outcome
✅ SafeClean, no decorative patterns on public methodsModel copies structure, no decoration
⚠️ Moderate1-2 decorative patterns on public methodsModel copies at 1:1 rate — each pattern transfers
❌ Dangerous3+ decorative patterns on public methodsModel copies aggressively, inoculation fails
🛡️ SafeDecorative patterns on PRIVATE methods onlyPatterns don't transfer — no shared surface area

What to clean:

  • Decorators on public methods — these transfer 1:1 (proven by density gradient experiments)
  • Import statements for utilities the new task doesn't need
  • Legacy compatibility code (aliases, deprecated signatures)
  • Over-engineered abstractions (retry wrappers, custom exception hierarchies) that aren't relevant to the new task

What is SAFE to leave:

  • Decorative patterns on private methods (_execute_request, _build_prompt) — these don't transfer because the new file doesn't have those methods
  • Architectural patterns (retry wrappers, custom error hierarchies, control flow) — these resist transfer because they require semantic understanding, not just pattern matching
  • Structural patterns (error handling flow, validation split)
  • Interface contracts (method signatures, return types)
  • Naming conventions
  • Docstring style

2. Avoid "Follow the Pattern" When Cargo Is Present

The phrase "follow the same patterns and conventions" is the single most dangerous instruction when exemplars contain cargo. Experiments showed it's the strongest cargo trigger.

Safe alternatives when exemplar is clean:

  • "Follow the same patterns and conventions you see" ← fine, nothing bad to copy
  • "Be structurally consistent with the existing code" ← same thing

Safe alternatives when exemplar has cargo:

  • "Implement the interface defined in base.py. Reference ollama.py for the general API structure, but adapt everything to the new context."
  • "Follow the structural approach (error handling, validation) but don't copy provider-specific patterns like decorators or metric names."
  • "Use the existing provider as a reference for the interface contract only."

3. Inoculation Is Fragile — Don't Rely On It

Telling the model "don't copy X" works in narrow conditions but can make things worse when exemplar density increases.

Exemplar DensityInoculation Result
0 patternsN/A (nothing to inoculate against)
1-2 patternsWorks, but causes overcorrection (drops ALL patterns)
3+ patternsREVERSES — inoculated prompts produce MORE cargo than uninoculated

Instead of inoculation, clean the exemplar. If you can't clean it, use targeted reference instructions (Principle 2) rather than negative instructions.

4. Be Specific About What to Reference

Vague references → cargo. Specific references → clean code.

Bad (vague):

"Look at ollama.py and do the same thing for Anthropic."

Good (specific):

"Read musa/ai/base.py for the interface you must implement. Read musa/ai/providers/ollama.py for an example of how one provider handles error translation and connection validation. Your Anthropic provider should use the anthropic Python SDK, not raw HTTP requests."

Best (scoped):

"Your task: implement AnthropicProvider following BaseAIProvider. Reference material: ollama.py shows the general pattern for error handling. Constraints: use the anthropic SDK, don't copy Ollama-specific patterns."

5. Specify the SDK/Library Explicitly

Models that see raw HTTP in exemplars may copy it even when a proper SDK exists. State the implementation tool upfront.

"Use the anthropic Python SDK (already installed)"

This prevents the model from copying the raw requests HTTP approach from a different provider.

6. Separate Interface from Implementation

Structure your prompt in layers:

  1. Interface layer: "Implement these methods with these signatures" (from base class / contract)
  2. Reference layer: "Here's an existing example for general approach" (exemplar file)
  3. Constraint layer: "But use X SDK, don't copy Y-specific patterns"

This prevents the model from treating the exemplar as a template to fill in, which is the mechanism behind cargo-culting.

7. Public Methods Are the Cargo Surface Area

Cargo only transfers across shared public methods. The maximum number of decorators that can transfer equals the number of public methods that exist in both the exemplar and the target file.

Implication: You don't need to scrub private helpers clean. A decorator on _execute_request() won't transfer because the new file doesn't have _execute_request(). Focus your cleanup on the public interface — call(), call_stream(), check_connection().

Corollary: More shared public methods = higher cargo capacity. A base class with 10 abstract methods can carry more cargo than one with 3.

8. Decorators Are the Gateway Drug — Architectural Patterns Resist Transfer

Surface syntax (decorators, annotations) transfers at near-100% rates. Architectural patterns (retry wrappers, control flow, custom error hierarchies) transfer at ~0–33%.

Cargo TypeTransfer RateMechanism
Decorators / Annotations~100%Pattern matching — easy to copy without understanding
Class constants + comments~33% ("ghost cargo")Shape transfers, substance doesn't
Architectural patterns (retry, backoff)~0%Requires semantic reasoning about why

Implication: If your codebase conventions live in decorators, they are maximally cargo-prone. If they live in control flow and architectural patterns, they are naturally resistant. When designing APIs for AI agents to implement, prefer architectural conventions ("wrap calls in a validation step") over decorative ones ("add @validated to each method").

Watch for ghost cargo: The model may copy surface markers of an architectural pattern (class constants like MAX_RETRIES = 3) without copying the actual implementation. These unused constants are a weaker form of cargo — present but harmless. They signal the model saw the pattern but chose not to implement it.

9. Models Can Articulate Why They Reject Patterns

When the pattern is semantically rich (retry logic, not a decorator), models sometimes produce conscious rejections — explicit comments explaining why the pattern wasn't copied:

# Anthropic API doesn't need retry logic in the same way Ollama does
# because their SDK has built-in retry logic for transient errors

This is a positive signal. It means the model evaluated the pattern's relevance and made a deliberate choice. When you see these comments in AI-generated code, it's evidence of reasoning, not cargo.

Implication: If your prompt asks the model to "follow patterns" and the output has no commentary about pattern choices, the model may be copying reflexively. If it has explicit reasoning about what to adopt and what to skip, that's healthier.

10. Scaffolding Is the Strongest Defense

When you can't clean the exemplar, provide a pre-built skeleton for the target file. Experiment 13 showed scaffolding is the only defense that produced zero cargo across both models — no decorators, no Ollama-specific error handling, nothing.

The skeleton should have:

  • Correct class structure and imports
  • Method signatures matching the interface contract
  • Docstrings explaining purpose
  • raise NotImplementedError in method bodies (or similar placeholder)
  • No decorative patterns — this is what makes it effective

The model simply fills in the method bodies. By removing the pattern-matching temptation entirely, scaffolding eliminates the mechanism that causes cargo-culting.

Example scaffold:

class AnthropicProvider(BaseAIProvider):
    def __init__(self, model: str, api_key: str):
        self.provider = "anthropic"
        self.model = model
        self._client = anthropic.Anthropic(api_key=api_key)

    def check_connection(self) -> bool:
        # TODO: Implement connection check
        raise NotImplementedError
    # ... etc

11. Self-Review Is an Effective Safety Net

A two-step generate-then-review process catches cargo that slipped through generation. Experiment 13 showed the review step successfully removed all 3 decorators that GLM-5.1 had generated in step 1.

The review prompt should be explicit:

"Review this file for patterns copied from [EXEMPLAR] that don't belong. Check for: decorators, error handling patterns, constants, or imports that are specific to [EXEMPLAR_PROVIDER]. Remove anything that doesn't belong."

Caveat: Self-review only helps if the model generated cargo in the first place. If the model was already clean, the review is redundant. Use it as a safety net, not a primary defense.

12. Code-Level Defenses Are Model-Dependent

Anti-pattern comments in code (e.g., # ⚠️ DO NOT COPY THIS) are not reliable across models. In Experiment 13:

  • GLM-4.7 respected the anti-pattern comments → 0 decorators (full defense)
  • GLM-5.1 ignored the anti-pattern comments → 3 decorators (same as baseline)

This means code-level warnings cannot be a recommended defense strategy — what works for one model may completely fail for another. Prefer structural defenses (scaffolding) or process defenses (self-review) that work regardless of model behavior.

13. Model Choice Is Your Strongest Lever — But Not the Only One

Early cargo experiments showed a very large gap between model families. That remains true: stronger models still reduce many forms of shallow cargo and often produce cleaner outputs.

But later Musa experiments (especially the medium-task provider experiments) refine this claim. On architecture-sensitive work, all tested model families still responded to exemplar steering:

  • neutral runs drifted toward SDK-oriented / Anthropic-like providers
  • Ollama-anchored runs drifted toward raw HTTP providers
  • this happened across GPT and GLM models

So the updated rule is:

  • model choice affects execution quality, test thoroughness, and reasoning clarity
  • exemplar choice often determines the architecture direction
FactorWhat it mainly changes
Model choicequality of execution, boundedness, cleanup burden
Exemplar choicedirection of architecture, transport strategy, exception shape
Scaffoldingscope discipline and integration spread
Reviewsemantic trust and proof of behavior

Implication: Before investing time in prompt engineering, first decide:

  1. is the baseline clean?
  2. what exemplar am I foregrounding?
  3. what model am I using?

A strong model helps a lot, but it does not make exemplars neutral.

Defense Hierarchy

Ranked from weakest to strongest, incorporating both the early cargo experiments and the later Musa medium-task experiments:

RankDefenseEffortMain benefitModel-Dependent?
0NoneNoneNo protection—
1Inoculation ("don't copy X")LowSometimes blocks surface cargoYes
2Anti-pattern comments in codeLowUnreliable warning signalHighly
3Better modelLowImproves execution quality and reduces shallow cargo—
4Specific exemplar scopingLow-MedReduces accidental architecture steeringNo
5Self-review / adversarial reviewMediumImproves semantic trust and catches missing proofNo
6Scaffolding (pre-built skeleton)MediumTightens scope and reduces integration spreadNo
7Clean baseline + intentional exemplar choiceMediumPrevents contamination and controls architecture directionNo

The meta-pattern: better models help, but on medium architecture-sensitive tasks the strongest controls are baseline cleanliness, intentional exemplar choice, scaffolding, and separate review.

Prompt Templates

Template: From delegation-coach handoff brief

Use this task framing to write the final coding prompt:

Task class: [TASK_CLASS]
Workflow: [WORKFLOW]
Exemplar guidance: [EXEMPLAR_GUIDANCE]
Constraints: [CONSTRAINTS]
Validation: [VALIDATION]
Review lens: [REVIEW_LENS]

Write the final prompt for the coding agent using a clear layered structure.

Template: New Provider / Module Alongside Existing

You are implementing a new [TYPE] for the [PROJECT] project.

The project has an existing [TYPE] at [EXEMPLAR_PATH] and a base interface at [BASE_PATH].

Your task: Implement a new [NAME] at [TARGET_PATH] and its tests at [TEST_PATH].

Requirements:
- Follow the interface from [BASE_PATH]
- Use the [SDK_NAME] SDK (already installed)
- Implement: [METHOD_LIST]
- Handle errors properly with [ERROR_TYPES]
- Write comprehensive unit tests mocking the [SDK_NAME]

[IF EXEMPLAR IS CLEAN:]
Study [EXEMPLAR_PATH] for the general approach and follow its conventions.

[IF EXEMPLAR HAS CARGO:]
Read [BASE_PATH] for the interface contract. Reference [EXEMPLAR_PATH] for the general
structure of error handling, but adapt everything to the new context. Do NOT copy
[PROVIDER]-specific patterns.

After implementation, run: [TEST_COMMAND]

Template: Feature in Existing Module

Add [FEATURE] to [MODULE_PATH].

First, read [MODULE_PATH] to understand the current structure and [RELATED_FILE] for context.

Requirements:
- [REQUIREMENT_1]
- [REQUIREMENT_2]
- Follow the existing code style in the module
- Add tests at [TEST_PATH]

Focus on: [SPECIFIC_BEHAVIOR]
Do NOT: [NEGATIVE_CONSTRAINT — use sparingly, only when exemplar has cargo]

After implementation, run: [TEST_COMMAND]

Template: Bug Fix

Fix the bug where [SYMPTOM] occurs when [CONDITION].

Reproduction: [STEPS]

First, read [FILE_PATH] and understand the current logic. The expected behavior is:
[EXPECTED_BEHAVIOR]

Fix the issue with minimal changes. Don't refactor surrounding code unless it's directly
related to the bug.

Add or update a test that would have caught this bug.

After implementation, run: [TEST_COMMAND]

Prompt Audit Checklist

When reviewing a prompt before sending it to an AI coding agent:

CheckQuestionAction
☐ Model profileIs your model stronger or weaker on cargo-prone work?Stronger = cleaner execution; weaker = more literal copying risk, but exemplars still matter for all models (Principle 13)
☐ Exemplar stateDoes the exemplar file contain decorative patterns?Clean it first (Principle 1)
☐ Public vs privateAre decorative patterns on public or private methods?Private is safe; public must be cleaned (Principle 7)
☐ Reference specificityIs "follow the pattern" used near cargo?Replace with specific reference (Principle 4)
☐ SDK specifiedIs the implementation tool/library stated?Add it explicitly (Principle 5)
☐ Scope boundedIs it clear what's interface vs implementation?Use layered structure (Principle 6)
☐ Inoculation usedAre there "don't do X" instructions?Consider removing — fragile (Principle 3)
☐ Test commandIs the exact test command specified?Add it to prevent guesswork
☐ Baseline cleanIs the repo/environment/branch state clean enough for the task?Freeze baseline first — a good prompt cannot rescue contamination
☐ Exemplar steeringAre you intentionally choosing the exemplar for the architecture you want?Treat examples as steering inputs, not neutral context
☐ Scaffold possibleCan you provide a pre-built skeleton?Strongest defense for scope control — use it (Principle 10)
☐ Review step plannedIs there a generate-then-review cycle?Add self-review or adversarial review as safety net (Principle 11)
☐ Code-level warningsAre you relying on # DO NOT COPY comments?Unreliable — use structural defenses (Principle 12)

Anti-Patterns

Anti-PatternWhy It's DangerousWhat To Do Instead
"Follow the same pattern"Strongest cargo trigger when exemplar has decorative patternsBe specific about WHAT to follow
Inoculation at high densityCan reverse and increase cargoClean the exemplar instead
Vague file referencesModel treats entire file as templateScope the reference to specific patterns
No SDK specificationModel copies HTTP approach from different providerState the tool explicitly
"Do it however you want"Missed opportunity to guide toward good patternsSpecify interface + constraints, leave implementation free
Long negative lists"Don't do X, don't do Y, don't do Z" dilutes signalFix the exemplar so negatives aren't needed
Scrubbing private helpersWasted effort — private method patterns don't transferFocus cleanup on public methods only
Scrubbing architectural patternsWasted effort — retry wrappers and control flow resist transfer naturallyFocus cleanup on decorators and annotations instead
Ignoring ghost cargoUnused constants/comments from exemplar signal incomplete reasoningReview for dead code that references other providers
Relying on anti-pattern commentsModel-dependent — one model respects them, another ignores themUse scaffolding or self-review instead
Trusting inoculation for semantic cargoInoculation blocks surface patterns but deeper patterns leak throughUse scaffolding for full protection
Assuming all models copy equallyModels differ in output quality and cargo behaviorCheck both model profile and exemplar risk
Assuming a strong model makes exemplars safeLater Musa experiments show exemplar steering still changes architecture across GPT and GLMChoose exemplars intentionally even on strong models
Prompt-engineering around a bad baselineBaseline contamination invalidates conclusions no matter how good the prompt isFreeze repo/environment/branch state first
Prompt-engineering around a bad modelBetter models help, but framing still determines directionImprove model choice and exemplar choice together

When to Use This Skill

  • Before delegating to a subagent — craft the prompt using these templates
  • Before sending a task to an AI coding tool — audit for cargo risk
  • When code reviews show copy-paste patterns — the prompt likely caused it
  • When onboarding a new AI tool — set up clean exemplars first
  • When refactoring — clean exemplars before asking AI to create new modules
  • When designing APIs for AI agents — prefer architectural conventions over decorators
  • When reviewing AI-generated code — check for ghost cargo (unused constants from exemplar)

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.