scratch-org
Skill1 starsChanged 7 months agoMITView on GitHub
Create or destroy a Salesforce scratch org from `config/project-scratch-def.json`, optionally deploy the project, optionally seed with the project's TestDataFactory. Useful for clean-slate testing, CI runs, and onboarding new developers.
In this repository53 other files it gives its agents.
- templates/CLAUDE.mdCLAUDE.md
- adrSkill
- agent-deploySkill
- agent-discoverSkill
- agent-eval-trendSkill
- agent-exchange-listSkill
- agent-specSkill
- agent-testSkill
- agent-vs-flow-vs-apexSkill
- before-vs-after-triggerSkill
- code-reviewSkill
- complexitySkill
- coverage-trendSkill
- dead-codeSkill
- dependency-graphSkill
- deploySkill
- destructive-changesSkill
- diff-deploySkill
- erdSkill
- field-impactSkill
- flaky-test-finderSkill
- flow-auditSkill
- flow-vs-apexSkill
- fls-auditSkill
- gateway-configSkill
- generate-docsSkill
- limit-usageSkill
- lwc-vs-reactSkill
- mcp-tool-vs-restSkill
- notifySkill
- onboardSkill
- org-diffSkill
- org-exploreSkill
- package-versionSkill
- pattern-packSkill
- perf-reviewSkill
- permset-auditSkill
- pr-prepareSkill
- queueable-vs-batchSkill
- quick-deploySkill
- react-initSkill
- release-notesSkill
- security-scanSkill
- sequence-diagramSkill
- sf-initSkill
- sharing-reviewSkill
- slack-agentSkill
- soql-analyzerSkill
- test-coverageSkill
- test-dataSkill
- test-planSkill
- trust-evalSkill
- trust-layer-auditSkill
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 0 are distinctive, and 6 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 17
If platform.devHubAlias is not set in sf-project.json, fall back to DevHub.
- Very specific: line 68
Check if force-app/.../classes/TestDataFactory.cls exists
- Very specific: line 69
If yes, run anon-Apex that calls a per-project seed() method (the factory should expose one).
- Very specific: line 76
If botDefinitions/ exists in source, also run the agent seed:
- Very specific: line 139
Refuse to destroy non-scratch orgs: Verify via sf org list that the alias is in scratchOrgs[]
- Very specific: line 141
Honor the project's
paths.apexSource: when looking for TestDataFactory to seed
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 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.
Files
You are creating or destroying a scratch org for the project. Scratch orgs are short-lived (max 30 days), feature-flag-controlled Salesforce instances tied to a Dev Hub. They're the right tool for CI tests, integration tests, and clean-slate dev work.
Read Project Config First
source "${CLAUDE_PLUGIN_ROOT}/hooks/lib/config.sh"
DEV_HUB="$(sf_config_get '.platform.devHubAlias // \"DevHub\"' "$ENV")"
DEFINITION="${SCRATCH_DEF:-config/project-scratch-def.json}"If platform.devHubAlias is not set in sf-project.json, fall back to DevHub. Recommend adding it to the config for clarity.
Input
$ARGUMENTS:
create [<alias>]— create a scratch org with the given alias (default: timestamp-based)destroy <alias>— delete the named scratch orglist— list scratch orgs the user ownsrecreate <alias>— destroy + create with the same alias--days <n>— duration (1–30, default 7)--no-deploy— create only, skip the source push (default: push)--no-seed— skip running TestDataFactory anonymous Apex (default: seed if a factory exists)--definition <path>— override the scratch def path--ci— machine output
Steps
create [<alias>]
- Verify Dev Hub is logged in:
sf_cli_alias_exists "$DEV_HUB" || { echo "[scratch-org] Dev Hub '$DEV_HUB' not authenticated. Run: sf org login web --alias $DEV_HUB --set-default-dev-hub" >&2; exit 2; } - Verify scratch definition exists:
[[ -f "$DEFINITION" ]] || { echo "[scratch-org] Scratch definition not found: $DEFINITION" >&2; exit 2; } - Generate alias if not provided:
ALIAS="${1:-$(printf 'scratch-%s' "$(date +%Y%m%d-%H%M%S)")}" - Create the scratch org:
sf org create scratch \ --target-dev-hub "$DEV_HUB" \ --definition-file "$DEFINITION" \ --alias "$ALIAS" \ --duration-days "${DAYS:-7}" \ --set-default \ --json - Push source (unless
--no-deploy):sf project deploy start --target-org "$ALIAS" --wait 30 - Seed test data (unless
--no-seed):- Check if
force-app/.../classes/TestDataFactory.clsexists - If yes, run anon-Apex that calls a per-project
seed()method (the factory should expose one). If the factory doesn't have aseed(), skip with a note
The bundledsf apex run --target-org "$ALIAS" --file "${CLAUDE_PLUGIN_ROOT}/templates/scratch/seed.apex"seed.apexcallsTestDataFactory.seed();if the method exists; the user is encouraged to define it. - Check if
- Seed agent test data (unless
--no-seed-agents, when the project has agents):- If
botDefinitions/exists in source, also run the agent seed:
The bundledsf apex run --target-org "$ALIAS" --file "${CLAUDE_PLUGIN_ROOT}/templates/scratch/seed-agents.apex"seed-agents.apexcallsTestDataFactory.seedAgents();if defined. Agent eval suites typically need richer data (Cases with rich context, Orders with edge-case fields populated) than plain unit tests — defineseedAgents()on your factory to make scratch-org eval runs representative. - If
- Open the org (only in interactive mode, not
--ci):sf org open --target-org "$ALIAS"
destroy <alias>
sf org delete scratch --target-org "$alias" --no-promptConfirm the alias matches a scratch org (not a prod alias) before deleting.
list
sf org list --json | jq '.result.scratchOrgs[] | {alias, expirationDate, status, instanceUrl}'recreate <alias>
destroy <alias> then create <alias> with the same flags.
Output
Default Markdown:
# Scratch Org: scratch-20260428-141500
✅ Created via Dev Hub: DevHub (10.2s)
Username: test-xyz@example.com
Instance URL: https://....scratch.my.salesforce.com
Expires: 2026-05-05 (7 days)
✅ Source deployed (62.4s) — 137 components
✅ Seed data inserted (3.1s) — 50 Accounts, 200 Contacts, 50 Orders
## Next steps
- Open: sf org open --target-org scratch-20260428-141500
- Run tests: /argo:test-coverage all --target-org scratch-20260428-141500
- Destroy: /argo:scratch-org destroy scratch-20260428-141500CI mode: emit one JSON line per phase with timing.
Bundled seed template
The plugin ships templates/scratch/seed.apex (created by Phase 7 commit). It's a 5-line wrapper that calls TestDataFactory.seed() if defined. Users override by adding their own seed() method to their factory.
Exit codes
- 0 — operation succeeded
- 1 — partial success (e.g., create succeeded but deploy failed); the org exists, user should investigate
- 2 — invocation error (Dev Hub not auth, definition missing, etc.)
Rules
- Default duration is short. 7 days, not 30. Long-lived scratches drift; if the user needs longer, they can pass
--days 30 - Prefix scratch alias with
scratch-. Makes it impossible to accidentallydestroya prod alias - Refuse to destroy non-scratch orgs. Verify via
sf org listthat the alias is inscratchOrgs[] - Don't push to a scratch with
--no-deploy. The user explicitly opted out - Honor the project's
paths.apexSourcewhen looking forTestDataFactoryto seed
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
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.

