Work Pricing FAQ Blog Jobs Trending Book the AI Audit

HomeBlogHow to Build CRM Workflow Automation with Claude Code

How to Build CRM Workflow Automation with Claude Code

Most small businesses run their sales process in a CRM like HubSpot, Pipedrive, or Monday.com. The CRM holds the data, but the actual work — routing leads, updating deal stages, triggering follow-ups — still happens manually or through clunky Zapier chains that break every few months. I've built CRM workflow automation with Claude Code for three clients in Vancouver this year, and the pattern is consistent: you can replace 80% of your manual CRM tasks with custom scripts that run faster, cost less, and don't require a middleware subscription.

Here's how I approach it, step by step, so you can do the same.

What CRM Workflow Automation Actually Means

Before we get into the technical setup, it's worth defining what we're automating. CRM workflow automation covers any repeatable task that happens in response to a change in your CRM data. Common examples:

  • Lead routing — assigning new leads to the right sales rep based on territory, deal size, or industry
  • Deal stage updates — moving a deal forward when a specific action occurs (contract signed, demo completed)
  • Follow-up sequences — triggering email or Slack reminders when a contact hasn't been touched in X days
  • Data enrichment — pulling company data from Clearbit or LinkedIn and writing it back to the contact record
  • Tagging and segmentation — applying labels based on engagement behavior or form responses

Most CRMs have native automation features, but they're limited. HubSpot workflows can do simple if-this-then-that logic, but anything with multi-step branching or external API calls gets messy fast. That's where Claude Code comes in — it gives you full control over the logic without needing to build a custom app or hire a developer.

Step 1: Map the Current Manual Workflow

The first step is documenting what you're currently doing by hand. I use a simple text outline that looks like this:

TRIGGER: New lead form submitted on website
ACTION 1: Check lead's company size field
  IF > 50 employees → assign to Enterprise team, tag "Enterprise"
  IF 10-50 employees → assign to Mid-Market team, tag "Mid-Market"
  IF < 10 employees → assign to SMB team, tag "SMB"
ACTION 2: Send Slack notification to assigned rep
ACTION 3: Add lead to appropriate email nurture sequence in HubSpot
ACTION 4: Log activity note: "Auto-routed by lead size on [date]"

This becomes your blueprint. Once you have it written out, it's clear what needs to happen in code. Most workflows I automate follow this structure: a trigger (new record, field update, time-based), a decision tree (if X then Y), and a series of write-back actions (update fields, create tasks, send notifications).

Why This Step Matters

If you skip documentation and go straight to code, you end up building something that doesn't match how your team actually works. I've seen this fail twice — once with a client who thought they wanted automated lead scoring, but really needed better manual segmentation. The other time, the workflow we built was technically correct but didn't account for edge cases like duplicate leads or contacts with missing data. Mapping it first surfaces those gaps.

Step 2: Connect to Your CRM's API

Every modern CRM has an API. HubSpot, Pipedrive, Salesforce, Close, Copper — they all expose endpoints for reading and writing data. The quality varies (HubSpot's is well-documented, Salesforce's is a nightmare), but Claude Code can work with any of them as long as you have an API key.

For most workflows, you'll need two types of API calls:

  • Read calls — fetching contact or deal data to make decisions
  • Write calls — updating fields, creating tasks, or adding notes

Here's a simplified example of what a HubSpot contact lookup looks like in a Claude Code script:

import requests

HUBSPOT_API_KEY = "your-api-key-here"
contact_email = "lead@example.com"

url = f"https://api.hubapi.com/contacts/v1/contact/email/{contact_email}/profile"
headers = {"Authorization": f"Bearer {HUBSPOT_API_KEY}"}
response = requests.get(url, headers=headers)

if response.status_code == 200:
    contact_data = response.json()
    company_size = contact_data["properties"]["company_size"]["value"]
    # Now you can route based on company_size
else:
    print("Contact not found")

Once you can read and write data via the API, the rest is just logic. Claude Code handles the decision-making layer — the "if company size is greater than 50" part — and then executes the write-back.

Step 3: Build the Logic Layer with Claude Code

This is where Claude Code shines. You don't need to write every conditional statement yourself — you describe the workflow in plain language, and Claude Code generates the logic. The prompts I use tend to look like this:

You are automating a CRM lead routing workflow. Given a contact record with these fields:
- company_size (integer)
- industry (string)
- lead_source (string)

Apply these routing rules:
1. If company_size > 50 and industry is "Technology", assign to rep_id 12345 and tag "Enterprise Tech"
2. If company_size between 10-50, assign to rep_id 67890 and tag "Mid-Market"
3. Otherwise, assign to rep_id 11111 and tag "SMB"

Return a JSON object with: assigned_rep_id, tags (array), and notes (string).

Claude Code outputs clean, testable logic. You can run it on sample data before connecting it to your live CRM, which avoids the "oops, I just routed 200 leads to the wrong person" problem that happens with Zapier when you misconfigure a filter.

Handling Edge Cases

The part that usually breaks in DIY automation is edge case handling. What happens if the company_size field is blank? What if a lead gets submitted twice in 10 minutes? Claude Code can be prompted to handle these explicitly:

If company_size is null or missing, default to SMB routing.
If a contact with the same email already exists, skip creation and append a note to the existing record instead.

These aren't afterthoughts — they need to be baked into the logic from the start. I learned this the hard way on a project where we didn't account for international phone number formats, and the script broke for every lead outside North America.

Step 4: Trigger the Workflow

Once the script works, you need a way to run it automatically. There are three common trigger patterns:

  • Webhook — your CRM sends a POST request to your script whenever a new lead is created
  • Polling — your script checks the CRM every X minutes for new records and processes them
  • Scheduled batch — your script runs once a day and processes everything that came in during the past 24 hours

Webhooks are cleanest but require a server. For most small business workflows, I use scheduled polling — a script that runs every 15 minutes via a cron job on a $5/month VPS. It's simple, reliable, and doesn't require real-time infrastructure.

One client I work with runs their entire lead routing system on a single Python script hosted on a DigitalOcean droplet. It polls HubSpot every 10 minutes, processes any new contacts, and writes back the routing assignments. Total cost: $6/month. The Zapier equivalent would have been $50/month and less flexible.

Step 5: Monitor and Iterate

The first version of any CRM automation script will have bugs. A field name changes. A team member leaves and their rep ID breaks the assignment logic. An edge case you didn't think of surfaces. This is normal.

I always build in basic logging — a text file or Google Sheet that records every action the script takes. For each lead processed, it logs:

  • Lead email and name
  • Routing decision made
  • Any errors encountered
  • Timestamp

This makes debugging simple. If a client says "I didn't get assigned this lead," I can check the log and see exactly what happened. Usually it's a data quality issue — the company_size field was blank, or the email was misspelled — but sometimes it's a logic bug. Either way, the log tells you where to look.

Real Example: Automating Follow-Up Sequences

The most requested workflow I build is automated follow-up reminders. Sales reps forget to follow up with warm leads, and deals stall. The manual solution is to set calendar reminders or use a CRM's built-in task system, but both require discipline.

Here's what I built for a Vancouver-based SaaS company:

  • Every day at 9am, the script pulls all deals in the "Demo Completed" stage
  • It checks the "last contacted" date for each deal
  • If it's been more than 3 business days, it creates a high-priority task for the assigned rep and sends a Slack DM
  • If it's been more than 7 days, it escalates to the sales manager

The entire script is about 120 lines of Python. It runs on a $5 VPS and hasn't failed once in four months. The result: their average follow-up time dropped from 6 days to 2 days, and they closed three deals that would have gone cold without the nudge.

Why This Beats Zapier or Make

I still use Zapier for simple one-step automations, but for anything that involves branching logic, multiple API calls, or custom data transformation, Claude Code is faster and cheaper. Here's the comparison:

  • Cost — Zapier Professional is $50–$100/month for multi-step workflows. A VPS running custom scripts is $5–$10/month.
  • Reliability — Zapier workflows break when APIs change or rate limits kick in. Custom scripts let you handle errors gracefully and retry failed operations.
  • Flexibility — Zapier's UI forces you into a linear "if this then that" model. With code, you can handle complex branching, loops, and conditional writes.

The tradeoff is setup time. A Zapier workflow takes 20 minutes to build. A custom script takes 2–3 hours the first time. But once it's built, it's yours — no monthly fees, no arbitrary task limits, and no risk of the platform changing their pricing or shutting down your account.

Getting Started: Pick One Workflow

If you want to try this, start with one repeatable task. Lead routing is a good first project because it's simple, high-value, and easy to test. Don't try to automate your entire CRM at once — that's how projects stall.

The workflow I recommend:

  1. Pick one manual task you do weekly (tagging contacts, updating deal stages, assigning leads)
  2. Document the current process in a step-by-step outline
  3. Test the API connection by fetching one record and printing the data
  4. Build the logic in Claude Code using sample data
  5. Run it manually on 5–10 real records and verify the results
  6. Set up a scheduled trigger and let it run for a week

After you've proven it works, expand to the next workflow. That's how I built out full CRM automation systems for clients — one workflow at a time, tested thoroughly, then layered together.

If this sounds like something you want for your business but don't want to build yourself, I do this as a service. And if you're not sure which workflow to start with, the FAQ page answers most of the common questions about scoping and pricing. You can also check out related guides on CRM integration strategies and sales email automation.

Work with me

Want this kind of result for your business?

Start with the AI Audit — $1,500. One focused engagement. The 3 highest-ROI opportunities in your business, ranked. A working proof-of-concept of the #1. Credited toward your build if we go forward.

Book the AI Audit → Read the FAQ
← All posts Book a call →