
How to build a prospecting agent in Claude Code
Building a prospecting agent inside Claude Code replaces static database queries with live, terminal-driven web research across company filings, job boards, and community discussions. Instead of paying per-credit fees to query outdated records, GTM engineers can run autonomous research loops directly in their local terminal using authenticated browser sessions. At Drevon, we built our free macOS prospect research app around local browser execution because primary sources on the live web consistently beat purchased contact spreadsheets.
Key Takeaways
- Command-line agents running in Claude Code turn existing AI subscriptions into active scrapers that read live primary sources rather than stale database dumps.
- Extracting authenticated session state via Chrome DevTools Protocol or persistent browser contexts allows agents to inspect protected pages without triggering anti-bot blocks.
- Structuring strict evidence schemas with mandatory source URLs prevents relation-error hallucinations and fabricated entity data.
- Connecting browser Model Context Protocol (MCP) servers introduces a 10,000 to 15,000 token schema tax that requires deliberate session and context management.
The Terminal-Native Prospecting Workflow
Traditional B2B data vendors charge recurring seat fees and consumption credits for access to centralized databases that decay continuously. When sales teams rely entirely on static aggregators, they send outreach based on six-month-old job titles and stale funding announcements. Terminal-based coding agents invert this dynamic by executing live web research directly from your machine.
Running an agent through Claude Code connects language model reasoning directly to local shell commands, browser controllers, and search scripts. When instructed to find companies exhibiting buying intent, the agent executes targeted search queries, navigates to relevant web pages, extracts verifiable facts, and writes structured records straight to your disk.
+-------------------------------------------------------------------+
| Claude Code CLI |
| (Task Planning, Prompt Logic, Context Compaction) |
+---------------------------------+---------------------------------+
|
+---------------------+---------------------+
| |
v v
+-----------------------+ +-----------------------+
| Playwright MCP Server | | Custom Shell Scripts |
| (Chromium CDP Attach) | | (Curl, Grep, SQLite) |
+-----------+-----------+ +-----------+-----------+
| |
v v
+-----------------------+ +-----------------------+
| Authenticated Browser | | Local Output Storage |
| (Active Cookie State) | | (prospects.csv / .db) |
+-----------------------+ +-----------------------+
This workflow eliminates per-record enrichment surcharges. Claude Code operates against developer plans such as Claude Pro ($20 per month), Claude Max 5x ($100 per month), Claude Max 20x ($200 per month), or direct Console API billing. On direct API usage, Claude Sonnet 5 is priced at $2.00 per million input tokens and $10.00 per million output tokens, while Claude Sonnet 4.6 runs at $3.00 per million input tokens and $15.00 per million output tokens. As detailed in Finout's breakdown of Claude Code pricing, Anthropic enterprise deployment telemetry indicates that active developers average approximately $13 per day ($150 to $250 monthly), with 90% of active developer days remaining below $30.

Core Architecture: Tools, Context, and Storage
A terminal prospecting agent requires three functional components: an execution runtime, an authenticated browser bridge, and a local structured datastore.
.
├── .claude/
│ └── mcp.json # MCP server configuration
├── scripts/
│ ├── auth_export.js # Session state exporter
│ └── search_helper.py # Pre-filtering query wrapper
├── prompts/
│ └── prospect_schema.md # System instructions and output schema
└── output/
└── prospects.csv # Verified evidence-backed results
Authentication and Session Management
Autonomous prospecting fails quickly if your agent cannot access gated web sources such as community forums, industry registries, or technical discussions. Attempting to scrape these platforms with raw HTTP requests triggers CAPTCHA challenges or login redirects.
The most reliable approach connects the agent to your active Chromium instance. As detailed in Steve Kinney's analysis of driving vs debugging browser workflows, attaching via Chrome DevTools Protocol (CDP) over a remote debugging port avoids OS-level cookie encryption and database file locks.
# Launch Google Chrome with a dedicated remote debugging port
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome \
--remote-debugging-port=9222 \
--user-data-dir="$HOME/Library/Application Support/Google/Chrome"
For headless agent runs where you prefer isolated instances, use Playwright to export a storage state snapshot from an authenticated session:
// scripts/auth_export.js
import { chromium } from 'playwright';
(async () => {
const browser = await chromium.launch({ headless: false });
const context = await browser.newContext();
const page = await context.newPage();
// Navigate to target domain and pause for manual login
await page.goto('https://www.linkedin.com/login');
console.log('Complete login in the opened browser window...');
await page.waitForURL('https://www.linkedin.com/feed/', { timeout: 120000 });
// Persist storage state to disk
await context.storageState({ path: 'auth_state.json' });
console.log('Authentication state saved to auth_state.json');
await browser.close();
})();
Alternatively, Anthropic's native integration allows linking the CLI with Chromium browsers through the Claude in Chrome extension, sharing authenticated sessions and pausing execution in the terminal whenever manual interaction is required.
Step 1: Define an Unforgiving Evidence Schema
Ungrounded language models frequently hallucinate factual data when extracting company attributes. In the Stanford HAI 2026 AI Index Report on responsible AI, evaluations across 26 frontier models recorded hallucination rates between 22% and 94% on uncalibrated queries depending on task complexity and model abstention thresholds. Furthermore, in Arize AI's LibreEval benchmark across 72,155 samples, the primary failure modes in retrieval systems were relation-error hallucinations (32.0%), incomplete field extraction (22.2%), overclaims (17.7%), and unverifiable statements (10.2%).
To prevent your agent from generating plausible but fabricated prospect details, enforce a strict output contract. The agent must reject any record that lacks an explicit quote and verifiable source URL.
Save the following specification as prompts/prospect_schema.md:
You are an autonomous GTM research agent. Your task is to identify qualified target accounts and verified technical leads based on verifiable web evidence.

### Strict Extraction Rules:
1. Every prospect record MUST contain an exact verbatim quote from a public primary source.
2. Every record MUST include the live, fully qualified URL where the quote was extracted.
3. If an attribute (such as email pattern or hiring intent) cannot be confirmed by direct source text, mark it as null. Do not infer, extrapolate, or guess.
4. Do not output unverified records. Discard any candidate company that does not satisfy all ICP requirements.
### Required Output Format:
For every qualified prospect found, append a row to `output/prospects.csv` with these exact columns:
- `company_name`: Legal or common trading name
- `domain`: Primary company web domain
- `contact_name`: Full name of the relevant decision maker
- `contact_role`: Exact current job title
- `intent_signal`: Summary of verified trigger event
- `verbatim_evidence`: Direct quote (max 200 characters)
- `source_url`: Verifiable URL where the quote was extracted
- `verified_at`: ISO-8601 UTC timestamp
Step 2: Connect MCP Servers and Search Tooling
Claude Code uses the Model Context Protocol to expose local tools and browser capabilities to the model. Install the official Microsoft Playwright MCP server, which provides browser automation primitives via accessibility snapshots and targeted click actions.
Add the Playwright MCP server to your local configuration using the CLI:
claude mcp add playwright npx @playwright/mcp@latest
You can review source code and architecture details in the microsoft/playwright-mcp repository on GitHub. When configured, your .claude/mcp.json file will register the server:
{
"mcpServers": {
"playwright": {
"command": "npx",
"args": ["@playwright/mcp@latest"]
}
}
}

Managing the Context Window Tax
General-purpose browser MCP schemas consume substantial token headroom. As analyzed in documentation on Claude context window and token limits, tool definitions for browser automation can consume 10,000 to 15,000 tokens of context overhead before the agent executes its first action.
Passing raw HTML dumps into Claude Code quickly saturates the standard 200,000 token context window. To avoid rapid context compaction and keep API costs low, have your agent run lightweight Node.js or Python helper scripts that extract clean text snippets before returning data to the terminal.
# scripts/parse_snippet.py
import sys
import trafilatura
def extract_clean_text(html_content):
return trafilatura.extract(html_content, include_links=True, output_format="txt")
if __name__ == "__main__":
raw_html = sys.stdin.read()
clean_text = extract_clean_text(raw_html)
print(clean_text[:4000]) # Cap snippet to 4,000 characters
Step 3: Execute, Validate, and Export Results
With your MCP tooling connected and prompt schemas defined, launch Claude Code in your terminal to execute an end-to-end prospecting run.
claude
Inside the Claude Code interactive prompt, provide your operational directive:
Readprompts/prospect_schema.md. Use the Playwright MCP server and search tools to identify 10 B2B engineering infrastructure companies in the United States that have posted job openings for "Staff Platform Engineer" or "Site Reliability Engineer" within the past 30 days. For each company, locate the Head of Infrastructure or VP of Engineering, extract the verbatim source evidence of hiring intent, and append the validated records tooutput/prospects.csv.
Reviewing Agent Execution Logs
During execution, monitor how the agent handles web navigation, rate limits, and page extraction:
[Tool: playwright_navigate] -> https://www.google.com/search?q=site:jobs.lever.co+"Staff+Platform+Engineer"
[Tool: playwright_evaluate] -> Extracted 12 job posting URLs
[Action] Navigating to target company career board...
[Warning] 403 Forbidden on raw request -> Falling back to authenticated browser session
[Tool: playwright_navigate] -> https://jobs.ashbyhq.com/example-infra/job/10928
[Verification] Matched signal: "Migrating Kubernetes control plane to multi-region AWS"
[Tool: write_file] -> Appended verified record for Example Infrastructure Inc. to output/prospects.csv
| Execution Step | Agent Action | Primary Failure Risk | Mechanical Mitigation |
|---|---|---|---|
| 1. Account Discovery | Executes site-specific search queries on job boards and registries | Generic search engine IP rate limiting | Route queries through localized search scripts or CDP session |
| 2. Intent Verification | Navigates to career pages and technical blogs | Stale job postings or expired listings | Parse publication metadata and require active application buttons |
| 3. Lead Identification | Searches professional directories for department heads | Outdated employment profiles | Cross-verify current company name against primary domain |
| 4. Schema Validation | Validates structured JSON fields against evidence rules | Hallucinating missing contact details | Discard records where verbatim_evidence fails string matching |
The final output is a clean CSV file grounded entirely in primary sources:
company_name,domain,contact_name,contact_role,intent_signal,verbatim_evidence,source_url,verified_at
Acme Cloud,acmecloud.io,Sarah Jenkins,VP of Infrastructure,Hiring Staff SRE,"Looking for a Staff SRE to manage our transition to multi-region EKS clusters",https://jobs.ashbyhq.com/acmecloud/post/48102,2026-09-09T14:22:10Z
DataFlow Systems,dataflow.dev,Marcus Vance,Head of Platform,Expanding telemetry pipeline,"Seeking senior engineers to scale our ClickHouse ingestion cluster",https://boards.greenhouse.io/dataflow/jobs/91823,2026-09-09T14:25:44Z
Practical Limitations and the Desktop App Alternative
Building a DIY prospecting agent in Claude Code provides complete architectural visibility, but running production prospecting pipelines via a raw CLI exposes distinct operational bottlenecks.
+-------------------------------------------------------------------------+
| Operational Bottlenecks in CLI Agents |
+-------------------------------------------------------------------------+
| 1. Context Window Tax: 10K-15K tokens consumed by raw tool schemas |
| 2. Session Rolling Caps: 5-hour prompt caps drained by parallel tasks |
| 3. Manual Script Maintenance: Constant updates for selector drift |
| 4. Token Management: API costs compound on unparsed HTML dumps |
+-------------------------------------------------------------------------+
- Context Window Saturation: Loading multiple page structures into an active CLI session consumes token headroom quickly. Large context loads slow down execution and increase per-prompt costs.
- Quota Depletion: Developer subscriptions share rolling prompt allowances across interfaces. Running multi-step web scraping workflows in Claude Code can drain your 5-hour interactive budget, as noted in documentation on Claude Code usage limits.
- Selector Maintenance: Web layouts shift frequently. Maintaining custom scraping scripts and debugging headless browser flags requires ongoing engineering effort.
| Feature / Dimension | Claude Code CLI Agent | Dedicated Desktop App (Drevon) | Cloud Database Vendors |
|---|---|---|---|
| Execution Environment | Local machine (CLI terminal) | Local machine (macOS desktop app) | Vendor cloud infrastructure |
| Data Recency | Live primary web sources | Live primary web sources | Static synced database |
| Pricing Model | Existing AI subscription / API tokens | Free (bring your existing AI plan) | Annual contract + credit consumption |
| Authentication Handling | Manual CDP or Playwright script setup | Native sandboxed browser sessions | None (vendor-provided data only) |
| Evidence Grounding | Enforced via custom system prompts | Built-in link verification on every field | Rare / unsupported |
| Maintenance Overhead | High (tool schemas, script updates) | Zero configuration out of the box | None (closed platform) |
If you need a solution that runs locally without managing MCP server configurations, consider Drevon. Drevon runs sandboxed agents inside your macOS browser environment, drives the AI models you already pay for, and automatically verifies every extracted data point against live web evidence.
Frequently Asked Questions
Can I run a Claude Code prospecting agent without an API key?
Yes. If you subscribe to Claude Pro ($20/month) or Claude Max plans, you can authenticate the Claude Code CLI directly against your Anthropic account without provisioning separate Console API credits. However, heavy automated scraping will consume your plan's rolling 5-hour prompt allowance.
How do I prevent target websites from blocking my CLI agent?
Avoid running high-concurrency headless requests from bare IP addresses. Instead, connect your agent to a live, persistent browser profile using Chrome DevTools Protocol (--remote-debugging-port=9222). This reuses your established session cookies and browser fingerprint.
What is the difference between Playwright MCP and the native Chrome extension?
The Playwright MCP server launches programmatic Chromium, Firefox, or WebKit instances controlled via standardized accessibility trees. The Claude in Chrome extension integrates directly with your daily Google Chrome tabs, enabling shared logins and manual fallback prompts in the terminal.
How do I verify that extracted emails are valid?
Do not rely on language models to guess or generate email addresses. Use your agent to extract verified company email patterns from public disclosures, then pass generated candidates to local SMTP handshake verification scripts or dedicated validation libraries before loading them into your CRM.
Ready to automate evidence-backed prospect research without building custom terminal scrapers? Download Drevon for macOS to run local, session-authenticated GTM agents on your existing AI subscription.