Claude Code automation works best when Claude Code helps you build and check a small program, while a separate, dependable trigger runs it. This guide walks through a draft-only lead follow-up workflow: define its boundaries, have Claude Code build it, test it on sample data, and schedule it without automatically contacting prospects.
Table of Contents
- Choose a task and define what the workflow may do
- Decide what Claude Code builds and what runs it
- Set up a project and ask Claude Code for a small implementation
- Run a worked example from sample data to review queue
- Validate the exceptions and add safeguards
- Roll out gradually and measure whether it helps
- What to do first: write the workflow brief
Choose a task and define what the workflow may do
Start with a handoff, not “automate lead generation”
For a coach or agency, a useful first task is turning a form export into a queue of follow-up drafts for a person to review. Keep sourcing, qualification, drafting, sending, and CRM updates separate in your plan: each involves different data and consequences. This example covers only preparing drafts from records you already have.
Before opening Claude Code, write a short specification that identifies the input, output, and owner. For example: read a CSV with a contact name, email, and enquiry summary; write a draft and a review status to a separate file; route incomplete records to a human. Do not send messages or alter the original records.
- Input rules: name and email must be present; a missing enquiry summary should be flagged, not invented.
- Output rules: create one draft per valid record, with a clear review status.
- Stop conditions: stop or flag the run if the file cannot be read or the output cannot be written.
- Ownership: name the person who reviews drafts and investigates failures.
Use synthetic or anonymised examples while developing. Decide where real data may be stored and what information is needed before connecting a live form or CRM. Do not put credentials or unnecessary personal details in prompts, source files, or logs.
Decide what Claude Code builds and what runs it
Keep development separate from the business trigger
Claude Code is a coding agent for working with a codebase and running development tasks; it is not, by itself, a scheduled lead-processing service. Use it to create and maintain the script and tests, then select an execution mechanism—such as a manual run or a scheduled job—to run the finished script. Anthropic’s Claude Code overview describes its coding workflow.
For a small team with a GitHub repository, GitHub Actions can run a workflow on a schedule or a manual event. Its workflow syntax reference explains the event configuration. Treat the schedule as a convenience, not a real-time guarantee; keep a manual way to start a run and assign someone to check its outcome.
| Decision | Starting choice for this example | Change it when |
|---|---|---|
| Trigger | Manual run while building; scheduled run after review | The process needs a different response time or the schedule is unreliable for the task. |
| AI and business logic | Use Claude Code to build the script; keep the first version’s output as a draft queue | You have separately designed and reviewed any model-generated content or automatic action. |
| Permissions | Read the input and write a separate output | A necessary integration needs more access, and its owner has checked the permissions and recovery plan. |
| Failures | Stop, preserve a useful error message, and notify the owner | A retry is safe and the workflow can prevent duplicate drafts. |
Decide who owns the trigger, credentials, and exceptions before scheduling anything. If the workflow later connects to a provider, request only the permissions the task requires. Google’s OAuth scopes reference explains the permissions an application requests for Google APIs; check the relevant provider’s documentation for its own access model.
Set up a project and ask Claude Code for a small implementation
Give it testable requirements
Create a project directory with a sample CSV, a script location, a test location, and a README for setup and run instructions. Start Claude Code from the project directory with the claude command. Then give it a bounded task, such as: “Build a Python script that reads a CSV with name, email, and enquiry_summary columns; validates required fields; writes valid records as draft-only rows to a new CSV; flags invalid rows without guessing; and includes tests for valid, missing, and duplicate records. Do not send messages or modify the input.”
Ask Claude Code to show the files it intends to change and explain how to run the tests. Review its proposed code, especially file paths, handling of duplicate records, and whether it accidentally adds a sending step. Claude Code can help write code, but generated code is not verified code; inspect it and run the checks yourself.
- Keep input and output paths explicit, so a run cannot silently overwrite the source file.
- Make the script report how many records were accepted, flagged, or failed.
- Keep the draft template separate from business facts; do not let the script invent services, prices, or promises.
Run a worked example from sample data to review queue
Make the first pass manual and observable
Use a synthetic CSV with one complete enquiry, one missing an email, and one repeated record. Ask Claude Code to implement the validator and draft-only output first, then inspect the resulting files. A valid row should produce an unsent draft and a review status; an invalid or duplicate row should be clearly flagged rather than silently discarded or processed twice.
Once the project includes the script and tests, use the run command documented in its README. For example, a project might use python scripts/build_drafts.py --input data/sample.csv --output out/drafts.csv, followed by python -m unittest. These commands are an implementation example: if Claude Code creates different file names or test tooling, use the commands in the reviewed README instead.
Do not connect a live trigger until the output matches the specification. For a scheduled GitHub Actions run, configure a schedule event and a manual event, then have the job check out the repository, set up the project’s required runtime, and run the same tested script. Review GitHub’s guidance on hardening Actions workflows before adding credentials or broader permissions. Store secrets in the platform’s supported secret mechanism, not in the repository.
Validate the exceptions and add safeguards
Test what happens when the workflow cannot proceed
A workflow is not ready just because it handled one complete enquiry. Test the failure path and duplicate path before real data or recurring runs. Check that an error is visible to the owner and that rerunning the job will not create a second draft for the same input.
- Required field missing: flag the row and say what needs attention.
- Duplicate submission: identify it using a defined key, such as a stable record ID if the source provides one; do not assume names alone are unique.
- Input file missing or unreadable: stop without producing a misleading “successful” result.
- Output write fails: report the failure and leave the source unchanged.
- Draft contains unsupported details: hold it for correction rather than approving or sending it.
Move from synthetic data to real inputs only after a person has checked the output and confirmed where it is stored. Keep approval distinct from execution: a reviewed draft should remain a draft unless a separately specified and tested process authorises sending. If you later add a CRM or email connection, verify its available permissions and test its failure behavior before enabling writes.
Roll out gradually and measure whether it helps
Track useful outcomes, not just successful runs
For an initial rollout, run manually or schedule the job in draft-only mode. Review each output and record defects by type—missing data, duplicate handling, unsuitable wording, or a technical error—so you can fix the cause instead of merely rerunning the same process. Pause the trigger if errors recur or the output is reaching the wrong reviewer.
Choose a review period as an illustrative starting policy, not a universal benchmark. For instance, a team might review every draft during its first 10 real runs. Extend that period if reviewers find recurring defects or if a mistake would have serious consequences; consider reducing the review burden only when the errors that matter are being caught and the exception route works.
Track a small set of measures that relate to the job: runs completed, runs failed, records flagged, duplicate drafts, drafts needing substantial edits, and time from run to review. Adjust based on the signal: repeated edits may mean the template or input rules need work; missed failures may mean the alert path is inadequate. Avoid logging credentials or personal details that are not needed to diagnose a problem.
What to do first: write the workflow brief
Before you schedule anything, write down the input fields, draft format, forbidden actions, failure owner, and sample cases. Then open Claude Code in a dedicated project, ask it to implement validation and draft-only output, and run the tests on synthetic data before connecting a live source.
Social Surge Media builds custom AI automation workflows with human approval steps and integrations tailored to client tools and processes; see its custom AI automation services page. Agencies evaluating a broader self-hosted operating layer can also review its Agentic OS for agencies page. For help assessing a workflow against your tools and approval needs, visit Social Surge Media.
Authored with NotFair SEO
