Route refund requests from Gorgias using a Claude Code skill

low complexityCost: Usage-based

Prerequisites

Compatible agents

This skill works with any agent that supports the Claude Code skills standard, including Claude Code, Claude Cowork, OpenAI Codex, and Google Antigravity.

Prerequisites
  • One of the agents listed above
  • Gorgias account with API access
  • Anthropic API key for Claude-powered refund classification
Environment Variables
# Your Gorgias subdomain (e.g. yourstore)
GORGIAS_DOMAIN=your_value_here
# Gorgias account email for API authentication
GORGIAS_EMAIL=your_value_here
# Gorgias API key from Settings > REST API
GORGIAS_API_KEY=your_value_here
# Anthropic API key for Claude refund intent classification
ANTHROPIC_API_KEY=your_value_here

Why a Claude Code skill?

The other approaches in this guide are deterministic: they run the same logic every time, the same way. An Claude Code skill is different. You tell Claude what you want in plain language, and the skill gives it enough context to do it reliably.

That means you can say:

  • "Route all unrouted tickets to the refund team if they're about refunds"
  • "Just show me which tickets look like refund requests — don't route anything yet"
  • "Also route exchange requests and store credit inquiries"
  • "How many refund tickets came in today?"

The skill contains workflow guidelines, API reference materials, and a classification prompt that the agent reads on demand. Because it uses Claude to classify intent rather than matching keywords, it catches refund requests phrased conversationally — "this isn't what I ordered and I want my money" — that keyword Rules would miss.

How it works

The skill directory has three parts:

  1. SKILL.md — workflow guidelines telling the agent what steps to follow, which env vars to use, and what pitfalls to avoid
  2. references/ — Gorgias API patterns (ticket endpoints, team assignment) so the agent calls the right APIs
  3. templates/ — a classification prompt template that shapes how Claude identifies refund intent

When invoked, the agent reads SKILL.md, consults the reference and template files as needed, writes a Python script that calls Claude's API for classification and the Gorgias API for routing, executes it, and reports results.

What is a Claude Code skill?

An Claude Code skill is a reusable command you add to your project that Claude Code can run on demand. Skills live in a .claude/skills/ directory and are defined by a SKILL.md file that tells the agent what the skill does, when to run it, and what tools it's allowed to use.

In this skill, the agent doesn't run a pre-written script. Instead, SKILL.md provides workflow guidelines and points to reference files — API documentation, a classification prompt — that the agent reads to generate and execute code itself. The generated script calls Claude's API directly for classification, so the outer agent handles orchestration while an inner Claude call handles the intent detection.

Once installed, you can invoke a skill as a slash command (e.g., /refund-routing), or the agent will use it automatically when you give it a task where the skill is relevant.

Step 1: Create the skill directory

mkdir -p .claude/skills/refund-routing/{templates,references}

This creates the layout:

.claude/skills/refund-routing/
├── SKILL.md                          # workflow guidelines + config
├── templates/
│   └── classification-prompt.md      # prompt for refund intent detection
└── references/
    └── gorgias-tickets-api.md        # Gorgias API patterns

Step 2: Write the SKILL.md

Create .claude/skills/refund-routing/SKILL.md:

---
name: refund-routing
description: Identify refund and return requests in unrouted Gorgias tickets using Claude, then assign them to the refund team and apply a tag via the Gorgias API.
disable-model-invocation: true
allowed-tools: Bash, Read
---
 
## Goal
 
Fetch unrouted open tickets from Gorgias, classify each one for refund/return intent using Claude (Haiku), and route matches to the refund team with a tag.
 
## Configuration
 
Read these environment variables:
 
- `GORGIAS_DOMAIN` — your Gorgias subdomain (required)
- `GORGIAS_EMAIL` — Gorgias account email for API auth (required)
- `GORGIAS_API_KEY` — Gorgias API key (required)
- `ANTHROPIC_API_KEY` — Anthropic API key for classification (required)
 
Default refund team name: "Refund Team". Default tag: "refund-request". The user may request different values.
 
## Workflow
 
1. Validate that all required env vars are set. If any are missing, print which ones and exit.
2. Fetch open tickets from Gorgias. See `references/gorgias-tickets-api.md` for the endpoint.
3. Filter to tickets with no team assignment and no existing `refund-request` tag.
4. For each ticket, read the subject and first 500 characters of the message body.
5. Call Claude (Haiku) with the classification prompt from `templates/classification-prompt.md` to determine if the ticket is a refund, return, or neither.
6. For tickets classified as REFUND or RETURN, assign to the refund team and merge the `refund-request` tag via `PUT /tickets/{id}`.
7. Print a summary of classified and routed tickets.
 
## Important notes
 
- The Gorgias `PUT /tickets/{id}` endpoint REPLACES the entire tags array. Fetch current tags first, merge `refund-request`, then PUT the combined list.
- The team assignment uses `assignee_team.name` in the PUT body. The name must match exactly what's configured in Gorgias Settings > Teams.
- Use claude-haiku-4-5 for classification — it's fast (~$0.001 per ticket) and accurate for binary classification.
- Rate limit: Gorgias allows roughly 2 requests per second.
- Use the `requests` library for Gorgias and `anthropic` for Claude. Install with pip if needed.

Step 3: Add reference files

templates/classification-prompt.md

Create .claude/skills/refund-routing/templates/classification-prompt.md:

# Refund Intent Classification Prompt
 
Use this prompt when calling Claude to classify a ticket.
 
## Prompt
 
```
You are a support ticket classifier. Determine if this ticket is a refund or return request.
 
Subject: {subject}
Body (first 500 chars): {body}
 
Reply with exactly one of:
- REFUND — customer wants money back, a refund, store credit, or reimbursement
- RETURN — customer wants to return, exchange, or replace an item
- NOT_REFUND — ticket is not about refunds or returns
 
Reply with only the label, nothing else.
```
 
## Notes
 
- Use `claude-haiku-4-5-20251001` as the model.
- Set `max_tokens: 20` — the response is a single word.
- Parse the response: if it contains "REFUND" or "RETURN", route the ticket.

references/gorgias-tickets-api.md

Create .claude/skills/refund-routing/references/gorgias-tickets-api.md:

# Gorgias Tickets API Reference
 
## Authentication
 
All requests use HTTP Basic Auth:
- Username: `GORGIAS_EMAIL`
- Password: `GORGIAS_API_KEY`
- Base URL: `https://{GORGIAS_DOMAIN}.gorgias.com/api`
 
## List open tickets
 
**Request:**
 
```
GET /api/tickets?status=open&limit=50
```
 
**Response shape:**
 
```json
{
  "data": [
    {
      "id": 14301,
      "subject": "I want a refund for order #7821",
      "status": "open",
      "assignee_team": null,
      "requester": {
        "id": 678,
        "firstname": "Sarah",
        "email": "sarah@example.com"
      },
      "tags": [],
      "messages": [
        {
          "id": 99001,
          "body_text": "Hi, I received my order but the item is damaged...",
          "source": { "type": "email" }
        }
      ]
    }
  ]
}
```
 
- Filter for `assignee_team == null` to find unrouted tickets.
- Filter out tickets that already have the `refund-request` tag.
 
## Update a ticket (assign team + tag)
 
**Request:**
 
```
PUT /api/tickets/{ticket_id}
Content-Type: application/json
```
 
**IMPORTANT:** The `tags` field REPLACES the entire array. Fetch current tags, merge in `refund-request`, then PUT the combined list.
 
**Body:**
 
```json
{
  "assignee_team": { "name": "Refund Team" },
  "tags": [
    { "name": "existing-tag" },
    { "name": "refund-request" }
  ]
}
```

Step 4: Test the skill

Invoke the skill conversationally:

/refund-routing

A typical run looks like:

Fetching unrouted open tickets...
Found 12 unrouted tickets to check
 
  #14301  "I want a refund for order #7821"       →  routed (REFUND)
  #14305  "Where is my package?"                   →  skipped (not a refund)
  #14308  "This arrived broken, I want my money"   →  routed (REFUND)
  #14312  "Can I exchange for a different size"     →  routed (RETURN)
 
Routed 3 of 12 tickets to Refund Team.

Because the agent generates code on the fly, you can also make ad hoc requests:

  • "Preview which tickets look like refund requests" — the agent classifies without routing
  • "Route to Billing Team instead of Refund Team" — the agent adjusts the team name
  • "How many refund tickets came in today?" — the agent pivots to analysis
Spot-check classifications

After the first run, review 10-15 classified tickets in Gorgias. Claude's intent detection is accurate for clear refund language, but edge cases (like complaints that might become refund requests) may need your judgment.

Step 5: Schedule it (optional)

Option A: Cron + Claude CLI

# Run every 30 minutes during business hours
*/30 8-18 * * 1-5 cd /path/to/your/project && claude -p "Run /refund-routing" --allowedTools 'Bash(*)' 'Read(*)'

Option B: GitHub Actions + Claude

name: Refund Request Routing
on:
  schedule:
    - cron: '*/30 13-22 * * 1-5'  # 8 AM-5 PM ET, weekdays
  workflow_dispatch: {}
jobs:
  route:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: anthropics/claude-code-action@v1
        with:
          prompt: "Run /refund-routing"
          allowed_tools: "Bash(*),Read(*)"
        env:
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
          GORGIAS_DOMAIN: ${{ secrets.GORGIAS_DOMAIN }}
          GORGIAS_EMAIL: ${{ secrets.GORGIAS_EMAIL }}
          GORGIAS_API_KEY: ${{ secrets.GORGIAS_API_KEY }}

Option C: Cowork Scheduled Tasks

Claude Desktop's Cowork supports built-in scheduled tasks. Open a Cowork session, type /schedule, and configure the cadence — hourly, daily, weekly, or weekdays only. Each scheduled run has full access to your connected tools, plugins, and MCP servers.

Scheduled tasks only run while your computer is awake and Claude Desktop is open. If a run is missed, Cowork executes it automatically when the app reopens. For always-on scheduling, use GitHub Actions (Option B) instead. Available on all paid plans (Pro, Max, Team, Enterprise).

Refund requests are time-sensitive

Refund tickets have higher urgency than general triage. Run every 15-30 minutes during business hours. For real-time routing, combine Gorgias native Rules for common keywords and use this skill to catch the edge cases Rules miss.

Troubleshooting

When to use this approach

  • You need semantic classification — Claude catches "this isn't what I ordered and I want my money" that keyword Rules miss
  • You want conversational flexibility — preview classifications, adjust routing targets, analyze refund volume
  • You're already using Claude Code and want skills that integrate with your workflow
  • You want to run tasks in the background via Claude Cowork while focusing on other work
  • You have multilingual customers whose refund requests don't match English keyword lists

When to switch approaches

  • You need instant routing (under 30 seconds) → use Gorgias Rules with keyword matching
  • You want a visual workflow builder → use n8n
  • You need routing running 24/7 at zero LLM cost → use Gorgias native Rules for common cases

Common questions

How accurate is Claude at detecting refund intent?

Very accurate for explicit requests ("I want a refund", "send it back"). For ambiguous cases ("this isn't working for me"), accuracy is around 85-90%. You can improve this by adding examples to the classification prompt or upgrading from Haiku to Sonnet.

Does this use Claude API credits?

Yes. Each ticket costs ~$0.001 to classify with Haiku. 500 tickets/month is about $0.50. The outer agent invocation adds $0.01-0.05 per run.

Can I add more classification categories?

Yes. Update the classification prompt to include additional labels (e.g., EXCHANGE, STORE_CREDIT, WARRANTY) and adjust the routing logic accordingly. Ask the agent conversationally: "Also detect warranty claims and route them to the warranty team."

Cost

  • Claude API (agent) — $0.01-0.05 per invocation
  • Claude API (classification) — ~$0.001 per ticket using Haiku
  • Gorgias API — included in all paid plans
  • GitHub Actions (if scheduled) — free tier includes 2,000 minutes/month

Looking to scale your AI operations?

We build and optimize automation systems for mid-market businesses. Let's discuss the right approach for your team.