agentleFS
jiten-singh-shahijiten-singh-shahi/salesforce-claude-code/.cursor/skills/strategic-compact/SKILL.md

strategic-compact

Skill15 starsChanged 7 months agoMITView on GitHub

Use when managing context during long Salesforce Apex development sessions. Suggests manual compaction at logical intervals to preserve deploy and org context across phases.

68 other projects use a version of this, 57 of them edited.

Adopted by

Most recently taken up by

Used with

Projects with it also use configure-ecc, ralphinho-rfc-pipeline and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • royaluniondesign-sysSkill

    configure-ecc

    Interactive installer for Everything Claude Code — guides users through selecting and installing skills and rules to user-level or project-level directories, verifies paths, and optionally optimizes installed files.

    Also in 11 projects that use this

  • junimnjwSkill

    ralphinho-rfc-pipeline

    RFC-driven multi-agent DAG execution pattern with quality gates, merge queues, and work unit orchestration.

    Also in 11 projects that use this

  • InfopibeSkill

    everything-claude-code

    Also in 11 projects that use this

  • TironFoxSkill

    openclaw-persona-forge

    为 OpenClaw AI Agent 锻造完整的龙虾灵魂方案。根据用户偏好或随机抽卡, 输出身份定位、灵魂描述(SOUL.md)、角色化底线规则、名字和头像生图提示词。 如当前环境提供已审核的生图 skill,可自动生成统一风格头像图片。 当用户需要创建、设计或定制 OpenClaw 龙虾灵魂时使用。 不适用于:微调已有 SOUL.md、非 OpenClaw 平台的角色设计、纯工具型无性格 Agent。 触发词:龙虾灵魂、虾魂、OpenClaw 灵魂、养虾灵魂、龙虾角色、龙虾定位、 龙虾剧本杀角色、龙虾游戏角色、龙虾 NPC、龙虾性格、龙虾背景故事、 lobster soul、lobster character、抽卡、随机龙虾、龙虾 SOUL、gacha。

    Also in 5 projects that use this

  • royaluniondesign-sysSkill

    content-hash-cache-pattern

    Cache expensive file processing results using SHA-256 content hashes — path-independent, auto-invalidating, with service layer separation.

    Also in 15 projects that use this

  • loulanyueSkill

    nuxt4-patterns

    Nuxt 4 app patterns for hydration safety, performance, route rules, lazy loading, and SSR-safe data fetching with useFetch and useAsyncData.

    Also in 9 projects that use this

The file

We split this skill into the rules it gives an agent

8 rules. 2 are common, 6 are distinctive, and 0 are very specific to this project.

  • 2

    Common

    Most of the 64 edited versions we read keep these.

  • 6

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When running long Salesforce development sessions that approach context limits (200K+ tokens)

    line 13
  2. Distinctive:

    When transitioning between distinct development phases (org exploration -> planning -> implementation)

    line 14
  3. Distinctive:

    When switching between unrelated Salesforce domains (Apex -> LWC -> Flow configuration)

    line 15
  4. Distinctive:

    After completing a major milestone (feature shipped, deployment succeeded) before starting new work

    line 16
  5. Common:

    When responses slow down or become less coherent due to context pressure

    line 17
  6. Common:

    No awareness of logical task boundaries

    line 24
  7. Distinctive:

    Instead of loading full skill content at session start, use a trigger table that maps keywords to skill paths.

    line 89
  8. Distinctive:

    Before compacting, write critical context to files so it survives:

    line 119

“Common” is measured: kept by at least 6 in 10 of the 64 edited versions of this file we could read. “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

Strategic Compact Skill

Suggests manual /compact at strategic points in your workflow rather than relying on arbitrary auto-compaction.

When to Use

  • When running long Salesforce development sessions that approach context limits (200K+ tokens)
  • When transitioning between distinct development phases (org exploration -> planning -> implementation)
  • When switching between unrelated Salesforce domains (Apex -> LWC -> Flow configuration)
  • After completing a major milestone (feature shipped, deployment succeeded) before starting new work
  • When responses slow down or become less coherent due to context pressure

Why Strategic Compaction?

Auto-compaction triggers at arbitrary points:

  • Often mid-task, losing important context about org structure or governor limits
  • No awareness of logical task boundaries
  • Can interrupt complex multi-step Salesforce operations (deploy pipeline, test runs)

Strategic compaction at logical boundaries:

  • After org exploration, before implementation — Compact metadata/schema context, keep implementation plan
  • After completing a feature — Fresh start for next feature
  • Before switching domains — Clear Apex context before LWC work

How It Works

The suggest-compact.js script runs on PreToolUse (Edit/Write) and:

  1. Tracks tool calls — Counts tool invocations in session
  2. Threshold detection — Suggests at configurable threshold (default: 50 calls)
  3. Periodic reminders — Reminds every 25 calls after threshold

Compaction Decision Guide

Phase TransitionCompact?Why
Org exploration -> PlanningYesOrg metadata is bulky; plan is the distilled output
Planning -> Apex implementationYesPlan is saved to a file; free up context for code
Apex implementation -> LWC workYesClear Apex context for unrelated frontend work
Apex implementation -> Apex testingMaybeKeep if tests reference recent code; compact if switching focus
Debugging -> Next featureYesDebug traces pollute context for unrelated work
Mid-implementationNoLosing class names, field APIs, and partial state is costly
After a failed deploymentYesClear the dead-end reasoning before trying a new approach
Trigger work -> Flow workYesDifferent domains with different context needs

What Survives Compaction

Understanding what persists helps you compact with confidence:

PersistsLost
CLAUDE.md instructionsIntermediate reasoning and analysis
Task list (if saved to a file)File contents you previously read
Project-level settings and rulesMulti-step conversation context
Git state (commits, branches)Tool call history and counts
Files on diskNuanced user preferences stated verbally
Org metadata on diskSOQL query results from exploration

Best Practices

  1. Compact after planning — Once plan is finalized and saved to a file, compact to start fresh
  2. Compact after debugging — Clear error-resolution context before continuing
  3. Don't compact mid-implementation — Preserve context for related Apex/LWC changes
  4. Read the suggestion — The hook tells you when, you decide if
  5. Write before compacting — Save important context (org structure, field APIs) to files or memory before compacting
  6. Use /compact with a summary — Add a custom message: /compact Focus on implementing trigger handler next

Salesforce-Specific Tips

  • Save org metadata before compacting — Object/field lists, record type IDs, profile names
  • Save governor limit findings — If you discovered limit issues, document them first
  • Save deployment results — Deployment errors/warnings should be saved before compacting
  • Keep test results accessible — Write failing test details to a file before compacting

Token Optimization Patterns

Trigger-Table Lazy Loading

Note: This is an aspirational optimization pattern -- SCC currently loads skills based on frontmatter triggers, not a runtime lazy-loading table.

Instead of loading full skill content at session start, use a trigger table that maps keywords to skill paths. Skills load only when triggered, reducing baseline context by 50%+:

Trigger KeywordsSkillLoad When
"test", "tdd", "coverage"sf-apex-testingUser mentions testing
"security", "sharing", "crud"sf-securitySecurity-related work
"deploy", "scratch org", "ci"sf-deploymentDeployment context
"soql", "query", "selectivity"sf-soql-optimizationQuery optimization
"trigger", "handler", "fflib"sf-trigger-frameworksTrigger development

Context Composition Awareness

Monitor what consumes your context window:

  • CLAUDE.md files — Always loaded, keep lean
  • Loaded skills — Each skill adds 1-5K tokens; SCC has 58 skills
  • Conversation history — Grows with each exchange
  • Tool results — File reads, SOQL results, test output add bulk
  • Rules — Always-on guidelines consume baseline context

Duplicate Instruction Detection

Common sources of duplicate context in SCC projects:

  • Skills that repeat CLAUDE.md instructions
  • Multiple skills covering overlapping domains (e.g., security guidance in both sf-security and sf-governor-limits skills)
  • Agent descriptions that duplicate skill content

Save-Before-Compact Examples

Before compacting, write critical context to files so it survives:

Save Org Metadata

# Save field list for target object
sf sobject describe --sobject Account --json > .claude/org-context/account-fields.json

# Save record type IDs
sf data query --query "SELECT Id, Name, DeveloperName FROM RecordType WHERE SobjectType = 'Account'" --json > .claude/org-context/record-types.json

Save Investigation Findings

<!-- .claude/session-notes.md — write before compacting -->
## Governor Limit Findings (2026-03-24)
- AccountTriggerHandler.cls line 45: SOQL in loop (CRITICAL)
- OrderService.cls: 3 DML statements could be combined (MEDIUM)
- Coverage: AccountService 82%, OrderService 61% (needs work)

## Deployment Blockers
- Missing field: Account.Risk_Category__c not in target org
- Flow "Auto Case Assignment" references deleted queue

Save Test Results

<!-- .claude/test-results.md -->
## Last Test Run
- 142/145 passing
- Failed: OrderServiceTest.shouldHandleBulkUpdate (NPE at line 89)
- Failed: CaseTriggerTest.shouldEscalateHighPriority (assertion at line 34)
- Failed: IntegrationTest.shouldCallExternalAPI (callout not mocked)
- Coverage: 78% org-wide

Multi-Session Continuity

For work spanning multiple sessions, use compact + session commands:

Session 1: Plan feature
  +-- /save-session -> saves plan, org context, findings
  +-- /compact -> clean slate

Session 2: Implement Apex
  +-- /resume-session -> restores plan context
  +-- [implement Apex classes]
  +-- /save-session -> saves implementation state
  +-- /compact

Session 3: Implement LWC + Deploy
  +-- /resume-session -> restores implementation context
  +-- [build LWC, deploy, verify]

Large Project Handling

For projects with 100K+ lines of code:

  • Don't read entire codebase — Use Grep/Glob to find specific files
  • Use codemaps — deep-researcher agent creates navigable index without loading full files
  • Compact aggressively between features — Each feature is a fresh context
  • Save architecture notes to files — Don't rely on conversation memory for class relationships
  • Use agents for parallel investigation — Subagents have their own context windows

Approximate Token Costs (as of the current API version per @../_reference/API_VERSIONS.md — may vary with model and encoding)

Content TypeApproximate TokensNotes
CLAUDE.md2-5KAlways loaded
Each rule file500-2KAll active rules loaded
Each loaded skill1-5KLoaded on demand
Apex class (500 lines)3-5KWhen Read tool is used
LWC component (3 files)2-4KHTML + JS + CSS
SOQL query result (100 rows)2-8KDepends on field count
Test output (full suite)5-15KUse --result-format human to reduce
Debug log (1000 lines)8-15KFilter with --log-level WARN

Related

  • suggest-compact.js hook — Automatic compaction suggestions
  • /save-session and /resume-session — State that survives compaction
  • sf-debugging skill — Debug context preservation
  • learning-engine agent — Extracts patterns before session ends

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.