Part V · Systems that run themselves · Chapter 15
Code and agents for GTM
How much code you need, what it unlocks, and where AI agents help versus where a script is safer.
12 min read
You can do a lot of GTM engineering without writing code. But a little code, especially written with an AI assistant, removes the ceilings that no-code tools hit: volume, cost, custom logic and data no tool connects to. And knowing how code works lets you check what AI builds for you, which is quickly becoming the core skill.
What you'll take away
- 01What code unlocks that no-code tools struggle with.
- 02The minimum you need to know, and how to learn it with AI help.
- 03How to build small tools with AI coding assistants, safely.
- 04When an AI agent is the right tool, and when a plain script is safer.
- 05How the Model Context Protocol connects AI tools to your systems.
Why a little code goes a long way
| Limit you hit | What code does |
|---|---|
| A table tool caps rows or charges per action | Process tens of thousands of rows cheaply on your own machine or a small server |
| The data you need has an API but no integration | Call the API directly |
| The logic is too complex to click together | Write it once, clearly, with tests |
| You need the same job every day, reliably | Schedule a script that logs what it did |
| You want to analyse results across campaigns | Query the data with SQL instead of exporting spreadsheets |
How much you need
- Reading and editing simple Python or JavaScript: loops, conditions, functions, lists and dictionaries.
- Calling an API: sending a request with a key and reading the JSON back.
- Reading and writing CSV files and spreadsheets.
- Basic SQL: select, filter, join, group. Many CRMs and warehouses let you query with it.
- Running code from a terminal, and keeping secrets in environment variables, not in the code.
That is weeks of learning, not years, especially with an AI assistant explaining each line. The goal is not to become a software engineer. It is to build and, above all, to check: to read what was written and see whether it does what you meant.
import csv
from urllib.parse import urlparse
def domain(url: str) -> str:
host = urlparse(url if "://" in url else "https://" + url).netloc.lower()
return host.removeprefix("www.")
seen, kept = set(), []
with open("leads.csv", newline="") as f:
for row in csv.DictReader(f):
d = domain(row["website"])
if d and d not in seen:
seen.add(d)
kept.append(row)
with open("leads_deduped.csv", "w", newline="") as f:
writer = csv.DictWriter(f, fieldnames=kept[0].keys())
writer.writeheader()
writer.writerows(kept)
print(f"kept {len(kept)} unique companies")Building with AI coding assistants
Tools like Claude Code can write, run and fix code from plain-language instructions in your terminal. They are excellent for GTM work: small, self-contained tools with clear inputs and outputs. Use them the way a careful engineer would.
- 1
Describe the job precisely
Inputs, outputs, edge cases and what 'done' means. The same discipline as a spec. - 2
Start on a small sample
Ten rows, not ten thousand, until the output is right. - 3
Read the code
Ask the assistant to explain anything unclear. Look for hard-coded keys, deletions and anything that writes to a live system. - 4
Test the edge cases
Empty cells, odd formats, duplicates, a failing API. - 5
Keep it in version control
So you can see what changed and undo it.
Agents: where they help, where scripts are safer
An agent is an AI system that decides its own next steps, choosing tools as it goes. Agents are impressive for open-ended research: investigate this account and summarise what matters. They are risky for repeatable bulk work, because their behaviour varies from run to run, they can lose track when given too much data at once, and their cost is hard to predict.
- Use a script when the steps are known: fetch, filter, enrich, score, write. It does the same thing every time and costs the same every time.
- Use AI inside the script for the steps that need judgment: classify this website, draft this line, with fixed answer formats (chapter 10).
- Use an agent for exploratory, one-off or low-volume work where the path genuinely varies, and review what it did.
Let code run the process and AI make the judgment calls inside it.
Connecting AI to your stack
MCP, the Model Context Protocol, gives AI assistants a common way to reach tools and data: your CRM, your enrichment provider, your spreadsheets. With an MCP connection an assistant can, for example, look up an account in the CRM while drafting an email. It is powerful and should be set up with care. Give the assistant read access by default, write access only where needed, and never connect it to systems where a mistake would be expensive without a person approving actions.
Try it
Choose the approach
For each job, choose a no-code table, a workflow tool, a script, or an agent, and say why.
- Every morning, pull new job ads for "head of finance" from a jobs API, filter by ICP and add matches to a sequence.
- Enrich and score a one-off list of 150 accounts for a sales leader by Friday.
- Investigate why one large prospect went quiet, using their news, hiring and our email history.
- Re-score all 40,000 CRM accounts every week.
Write your answer down first, then reveal the worked answerWorked answer
1. Workflow tool or script. A known, repeating process. Use a workflow tool if it is simple, a script if the filtering logic is complex. Either way, log runs and alert on zero results.
2. No-code table. Small, one-off and needed fast, which is exactly what tables are best at.
3. Agent, with a person reviewing. Open-ended research where the steps depend on what turns up.
4. Script. Large and repetitive, where per-row tool pricing would be expensive. Run it on a schedule with tests and a log.