Cloning an Existing Audience's Filter with the Clay CLI
Cloning an Existing Audience's Filter with the Clay CLI
Copy a working, workspace-specific filter AST from one saved audience straight into a new one, using Clay's real audiences get and audiences create --filter -, chained through jq with no hand-written field ids.
What you will build
A one-line pipeline that reads an existing audience's filter and uses it verbatim to create a second, independent audience.
clay audiences get <audience-id> | jq .filter
↓
clay audiences create --entity-type <type> --name <new-name> --filter -
↓
a new audience with an identical filter AST
AI Prompt
Using the Clay CLI, clone an existing audience's filter into a new audience.
Requirements:
- `clay audiences get <audienceId>` returns { id, name, description,
entityType, filter, createdAt, updatedAt }. "filter" is the audience's
ConditionalExpressionGroup AST, already stripped of UI-editor node ids --
it is safe to pipe directly into another command's --filter.
- `clay audiences create --filter -` accepts the filter from stdin (also
accepts inline JSON or a file path).
- The new audience's --entity-type must match what the cloned filter's
BinOp/ColOp nodes actually reference (their own "entityType": ACCOUNT/
CONTACT); cloning a companies filter into a --entity-type people audience
will not raise a hard type error but will not select the intended
records either -- keep entity-type consistent with the source audience.
- Run the verification step below before finishing.
Prerequisites
- The
clayCLI on PATH, authenticated viaclay login(an OAuth session, not a Public API key) jq- At least one existing audience to clone from
Note: JSON samples below are trimmed to the fields relevant to each step. Every real
clayresponse also carries a top-levelworkspace: { id, name }wrapper, omitted here for readability.
1. Read the source audience's filter
clay audiences get audseg_0tl84p1ZQ8RRShHSAdX | jq .filter
Real output:
{
"type": "GroupOp",
"combinationMode": "And",
"items": [
{"type": "BinOp", "key": "industry", "dataPath": ["account_entity_field_values", "field", "industry"], "operator": "Contain", "value": "Software", "entityType": "ACCOUNT"}
]
}
2. Pipe it directly into a new audience
clay audiences get audseg_0tl84p1ZQ8RRShHSAdX | jq .filter | clay audiences create --entity-type companies --name "TPC CLI Docs Test Companies (clone)" --filter -
The new audience is created with the exact same filter, key names, and data paths as the source: no hand-typed field ids, no risk of a typo in a workspace-specific key.
3. Verify the clone matches the same real record count
clay audiences records search-count --audience-id audseg_0tl84p1ZQ8RRShHSAdX --entity-type companies clay audiences records search-count --audience-id <new-audience-id> --entity-type companies
Both should report the same count. Confirmed live: both report 0 against this workspace's current company records, since the filter and entity type are identical.
Verify the result
Confirm the behavior above holds by re-running the key command and checking the result:
clay audiences get audseg_0tl84p1ZQ8RRShHSAdX | jq .filter | clay audiences create --entity-type companies --name clone --filter -
Expected: A new audience is created whose filter AST is byte-for-byte identical to the source audience's, confirmed by re-fetching both with clay audiences get.
How it works
An audience's filter field is intentionally returned free of UI-editor bookkeeping (ids that only matter to the drag-and-drop builder), which is exactly what makes it safe to round-trip through a command-line pipe. This sidesteps the single riskiest part of hand-writing a filter (getting a workspace-specific key/dataPath pair exactly right) by copying it from a filter that's already known to work.
Common issues
Cloning a filter into a mismatched --entity-type
Cause: assuming --filter alone determines what the audience selects, regardless of --entity-type.
Fix: keep entity-type consistent with the filter's own node-level entityType values (ACCOUNT for companies, CONTACT for people). A mismatch doesn't error. It just won't select the records you expect.
Re-typing field ids by hand instead of cloning
Cause: assuming it's simpler to write a fresh filter from a field list than to clone one.
Fix: key/dataPath are workspace-specific bookkeeping, not guessable from a field's display name: cloning from a real, working audience's filter avoids that class of mistake entirely.
Next steps
- Modify the cloned filter's
valuebefore creating, to build a related-but-different segment from a known-good base. - Use
clay audiences fields segments <fieldId>to see which audiences reference a field before changing or deleting it.
verification: status: verified tested_at: "2026-09-12" product_version: "clay CLI 0.19.0" command: "clay audiences get audseg_0tl84p1ZQ8RRShHSAdX | jq .filter | clay audiences create --entity-type companies --name clone --filter -" expected_result: "A new audience is created whose filter AST is byte-for-byte identical to the source audience's, confirmed by re-fetching both with clay audiences get."