fix-lifecycle-stages
Skill72 starsChanged 5 months agoMITView on GitHub
Ensure all contacts and companies have appropriate lifecycle stages. Backfills missing stages via API, fixes records stuck at disallowed stages, and creates prevention workflows to stop future gaps.
- Reads credentials
In this repository37 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- assign-unowned-contactsSkill
- audit-api-usageSkill
- backfill-geo-dataSkill
- bounce-monitoring-workflowSkill
- build-lead-scoringSkill
- build-smart-listsSkill
- cleanup-dashboardsSkill
- cleanup-dealsSkill
- cleanup-formsSkill
- cleanup-lead-ownersSkill
- cleanup-listsSkill
- cleanup-propertiesSkill
- cleanup-workflowsSkill
- connect-hubspot-mcpSkill
- create-icp-tiersSkill
- create-segment-listsSkill
- delete-no-email-contactsSkill
- engagement-suppression-workflowSkill
- enrich-company-nameSkill
- enrich-industrySkill
- hubspot-auditSkill
- hubspot-implementation-planSkill
- lifecycle-progression-workflowSkill
- merge-duplicate-companiesSkill
- new-contact-hygiene-workflowSkill
- quarterly-database-cleanupSkill
- reassign-deactivated-ownersSkill
- review-bounced-contactsSkill
- sandbox-self-testSkill
- standardize-geo-valuesSkill
- suppress-ghost-contactsSkill
- suppress-global-unsubscribesSkill
- suppress-hard-bouncedSkill
- waterfall-enrich-contactsSkill
- weekly-cleanup-routineSkill
- workflows-as-codeSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
14 rules. About 0 are common, 13 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈13
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 13
Ensure every contact and company has an appropriate lifecycle stage.
- Distinctive: line 71
Create prevention workflows for contacts and companies
- Distinctive: line 72
Verify 100% coverage (after state)
- Very specific: line 78
Run uv run skills/fix-lifecycle-stages/scripts/before.py.
- Distinctive: line 141
Do not set all missing contacts to "Lead" blindly.
- Distinctive: line 156
Create a list: Lifecycle stage is unknown AND Associated company lifecycle stage is Customer -> bulk edit to "Customer"
- Distinctive: line 157
Create a list: Lifecycle stage is unknown AND Associated company lifecycle stage is Opportunity -> bulk edit to "Opportunity"
- Distinctive: line 162
Check companies with associated deals:
- Distinctive: line 165
All remaining companies without a stage -> set to "Lead"
- Distinctive: line 193
Create another workflow: Company-based > Blank workflow
- Distinctive: line 202
If contacts keep getting set to disallowed stages (e.g., by imports or integrations):
- Distinctive: line 204
Create a workflow: Trigger = Lifecycle stage changed to "Subscriber" (or other disallowed value)
- Distinctive: line 221
Test the prevention workflow: create a test contact with no lifecycle stage, wait a few minutes, confirm it gets set to "Lead".
- Distinctive: line 237
The sub-list approach is important: Do not skip context-aware assignment and set everyone to "Lead".
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 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
Fix Lifecycle Stages
Ensure every contact and company has an appropriate lifecycle stage. This includes backfilling missing stages, correcting disallowed stage values, and creating prevention workflows that automatically assign stages to new records.
Why This Matters
Records without a lifecycle stage are invisible in pipeline reports, excluded from stage-based workflows, and cannot be properly segmented. Even a small percentage of missing lifecycle stages corrupts funnel reporting and makes pipeline analytics unreliable. Lifecycle stage data is also a prerequisite for lead scoring models and lifecycle progression workflows.
Prerequisites
- Phase 1 hygiene processes completed (invalid/deleted contacts removed first)
- A HubSpot private app access token (
HUBSPOT_ACCESS_TOKENin.env) with contact and company read/write scopes - Python 3.10+ with
uv - Access to Contacts and Companies with bulk edit permissions
- Access to Automation > Workflows
- Understanding of HubSpot's lifecycle stage progression rules (see Critical Concept below)
Scripts
| Stage | Script | Run with |
| Before | scripts/before.py | uv run skills/fix-lifecycle-stages/scripts/before.py |
| Execute | scripts/execute.py | uv run skills/fix-lifecycle-stages/scripts/execute.py |
| After | scripts/after.py | uv run skills/fix-lifecycle-stages/scripts/after.py |
before.py audits missing and per-stage counts for contacts and companies. execute.py performs the clear-then-set fixes (review its configuration block for the disallowed-stage mapping before running). after.py verifies coverage.
Critical Concept: Forward-Only Lifecycle Progression
HubSpot has forward-only lifecycle progression by default. The built-in order is:
Subscriber > Lead > MQL > SQL > Opportunity > Customer > Evangelist
To move a record from a later stage (e.g., "Other", "Evangelist") to an earlier one (e.g., "Lead"), you must:
- FIRST clear the lifecycle stage (set to blank/empty)
- THEN set the new value
A direct set to an earlier stage will be silently rejected — no error, no warning, the value simply does not change. This is the single most common gotcha when fixing lifecycle stages.
url = f"{BASE}/crm/v3/objects/contacts/{contact_id}"
# WRONG — silently fails if current stage is "later" than target
requests.patch(url, headers=HEADERS,
json={"properties": {"lifecyclestage": "lead"}})
# CORRECT — clear first, then set (two separate calls)
requests.patch(url, headers=HEADERS,
json={"properties": {"lifecyclestage": ""}})
requests.patch(url, headers=HEADERS,
json={"properties": {"lifecyclestage": "lead"}})Plan
- Audit missing and disallowed lifecycle stages (before state)
- Define which stages are "disallowed" for your business and map them to correct stages
- Fix contacts with disallowed stages (clear + re-set)
- Set missing stages to appropriate defaults based on associated company context
- Create prevention workflows for contacts and companies
- Verify 100% coverage (after state)
Before
Audit Script
Run uv run skills/fix-lifecycle-stages/scripts/before.py. The core queries it runs:
def count(object_type, filters):
resp = requests.post(f"{BASE}/crm/v3/objects/{object_type}/search",
headers=HEADERS,
json={"filterGroups": [{"filters": filters}], "limit": 1})
resp.raise_for_status()
return resp.json()["total"]
missing = count("contacts", [
{"propertyName": "lifecyclestage", "operator": "NOT_HAS_PROPERTY"}])
print(f"Contacts missing lifecycle stage: {missing}")
stages = ["subscriber", "lead", "marketingqualifiedlead", "salesqualifiedlead",
"opportunity", "customer", "evangelist", "other"]
for stage in stages:
n = count("contacts", [
{"propertyName": "lifecyclestage", "operator": "EQ", "value": stage}])
if n:
print(f" {stage}: {n}")
print(f"Companies missing lifecycle stage: "
f"{count('companies', [{'propertyName': 'lifecyclestage', 'operator': 'NOT_HAS_PROPERTY'}])}")Define Disallowed Stages
Decide which lifecycle stage values should not exist in your database. The table below shows common examples -- your disallowed stages and their correct mappings will depend on how your organization uses the CRM. Review your own stage distribution and decide what makes sense for your business:
| Example Disallowed Stage | Common Reason | Example Correct Stage |
| (empty/blank) | Invisible to reports | Lead (default) |
| Subscriber | Often misapplied when not used for newsletter-only contacts | Lead |
| Other | Meaningless catch-all | Lead |
| Evangelist | Rarely used correctly in most organizations | Customer (if actual customer) or Lead |
These are starting-point examples only. Your mapping will differ based on your sales process, integrations, and how stages are currently used. Define your specific mapping before executing.
Execute
Step 1: Fix Contacts at Disallowed Stages
For contacts at "Subscriber", "Other", or "Evangelist" that should be moved to "Lead":
# Pattern: Clear then set (required for backward movement)
DISALLOWED_TO_LEAD = ["subscriber", "other", "evangelist"]
for stage in DISALLOWED_TO_LEAD:
# Search for contacts at this stage
# Paginate through all results
# For each batch:
# 1. Clear lifecycle stage (set to "")
# 2. Set lifecycle stage to "lead"
# Use batch API for efficiency (100 per call)
passImportant: The clear-then-set must happen as two separate API calls. You cannot clear and set in one call.
Step 2: Set Missing Contact Stages with Context
Do not set all missing contacts to "Lead" blindly. Check their associated company context:
- Contacts at Customer companies -> set to "Customer"
- Contacts at Opportunity companies -> set to "Opportunity"
- All remaining contacts -> set to "Lead"
# Pattern for context-aware assignment:
# 1. Search for contacts with no lifecycle stage
# 2. For each, get their primary associated company
# 3. Check the company's lifecycle stage
# 4. Set the contact's stage to match (or "lead" as default)Manual approach via lists:
- Create a list: Lifecycle stage is unknown AND Associated company lifecycle stage is Customer -> bulk edit to "Customer"
- Create a list: Lifecycle stage is unknown AND Associated company lifecycle stage is Opportunity -> bulk edit to "Opportunity"
- Remaining contacts in the "no lifecycle stage" list -> bulk edit to "Lead"
Step 3: Fix Companies Without Lifecycle Stage
- Check companies with associated deals:
- Companies with closed-won deals -> set to "Customer"
- Companies with open deals -> set to "Opportunity"
- All remaining companies without a stage -> set to "Lead"
Step 4: Fix Stuck Records
Some records may fail to update due to the forward-only progression rule. Run a "fix stuck" script:
# Pattern: Find records that should be at a stage but are not
# For each:
# 1. Read current lifecycle stage
# 2. If current stage is "later" than target, clear first
# 3. Set the target stageStep 5: Create Prevention Workflows
Contact prevention workflow:
- Go to Automation > Workflows > Create workflow
- Select Contact-based > Blank workflow
- Name:
AUTO-FIX: Set Default Lifecycle Stage (Lead) - Enrollment trigger: Contact property > Lifecycle stage > is unknown
- Enable re-enrollment
- Action: Set contact property > Lifecycle stage > Lead
- Activate and enroll existing contacts
Company prevention workflow:
- Create another workflow: Company-based > Blank workflow
- Name:
AUTO-FIX: Set Default Company Lifecycle Stage (Lead) - Enrollment trigger: Company property > Lifecycle stage > is unknown
- Enable re-enrollment
- Action: Set company property > Lifecycle stage > Lead
- Activate and enroll existing companies
Optional: Disallowed stage correction workflows:
If contacts keep getting set to disallowed stages (e.g., by imports or integrations):
- Create a workflow: Trigger = Lifecycle stage changed to "Subscriber" (or other disallowed value)
- Action 1: Clear lifecycle stage (set to blank)
- Action 2: Set lifecycle stage to "Lead"
This prevents disallowed stages from recurring.
After
Re-run the audit: uv run skills/fix-lifecycle-stages/scripts/after.py. Both missing-stage counts (contacts and companies) should be 0.
Verification checklist:
- 0 contacts with missing lifecycle stage
- 0 companies with missing lifecycle stage
- 0 contacts at disallowed stages (Subscriber, Other, Evangelist, or whatever you defined)
- Spot-check contacts from Customer sub-list -> their lifecycle stage is "Customer"
- Spot-check contacts from Opportunity sub-list -> their lifecycle stage is "Opportunity"
- Test the prevention workflow: create a test contact with no lifecycle stage, wait a few minutes, confirm it gets set to "Lead". Delete the test contact.
- Funnel reports now show all records with no "unknown" bucket
Rollback
- The execute script's CSV audit trail records every record it changed with the original stage value. To undo, batch-update those IDs back to their previous stage (remember: moving backward requires the same clear-then-set pattern).
- Turn off the prevention workflows to stop automatic stage assignment.
Key Technical Learnings
- Forward-only progression is the biggest gotcha. Direct API updates to an "earlier" stage are silently rejected. You MUST clear first, then set. This applies to both API and workflow actions.
- "Lead" is the safest default. It is early in the progression and will not block forward movement from workflows or deal progression. "Subscriber" is NOT a good default unless you know the contacts subscribed to a newsletter.
- Context-aware assignment matters. Setting a contact at a Customer company to "Lead" instead of "Customer" degrades data quality. Take the time to check associated company context.
- Prevention is more important than cleanup. The prevention workflows ensure the problem never recurs. Without them, new records from imports, integrations, or manual entry will immediately re-create the gap.
- Lifecycle stage and deals interact. HubSpot can automatically advance lifecycle stage when deals are created or won. Your prevention workflows will not interfere because they only trigger when lifecycle stage is unknown.
- Batch edit limitations. The UI may time out on very large bulk edits. Process one page at a time, or use the API approach for large volumes.
- The sub-list approach is important. Do not skip context-aware assignment and set everyone to "Lead". Contacts associated with Customer or Opportunity companies deserve the correct stage.
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.

