Auto-triage Gorgias tickets 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 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 ticket 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:

  • "Triage all untagged tickets"
  • "Only classify tickets from the last 4 hours"
  • "Add an 'urgent' tag to anything that mentions a chargeback"
  • "What's the breakdown of ticket categories 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 tickets, it understands intent rather than matching keywords — catching "my parcel hasn't arrived" as a shipping issue even without the word "shipping."

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 listing, tag updates) so the agent calls the right APIs
  3. templates/ — a classification prompt that defines your tag categories

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 tagging, 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.

Once installed, you can invoke a skill as a slash command (e.g., /ticket-triage), 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/ticket-triage/{templates,references}

This creates the layout:

.claude/skills/ticket-triage/
├── SKILL.md                          # workflow guidelines + config
├── templates/
│   └── classification-prompt.md      # prompt for topic classification
└── references/
    └── gorgias-tickets-api.md        # Gorgias API patterns

Step 2: Write the SKILL.md

Create .claude/skills/ticket-triage/SKILL.md:

---
name: ticket-triage
description: Classify untagged open Gorgias tickets by reading subject and body, then apply a topic tag (billing, shipping, returns, technical, account, or feedback) via the Gorgias API.
disable-model-invocation: true
allowed-tools: Bash, Read
---
 
## Goal
 
Fetch untagged open tickets from Gorgias, classify each one by topic using Claude (Haiku), and write the tag back via the Gorgias API.
 
## 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 categories: billing, shipping, returns, technical, account, feedback, other. The user may request different categories.
 
## 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 existing tags.
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 the topic.
6. Apply the tag via `PUT /tickets/{id}`, merging with any existing tags.
7. Print each ticket ID, subject, and assigned tag.
 
## Important notes
 
- The Gorgias `PUT /tickets/{id}` endpoint REPLACES the entire tags array. Fetch current tags first, merge the new tag, then PUT the combined list.
- Use claude-haiku-4-5 for classification — it's fast (~$0.001 per ticket) and accurate for topic classification.
- If Claude returns a category not in the defined list, default to "other".
- 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/ticket-triage/templates/classification-prompt.md:

# Ticket Classification Prompt
 
Use this prompt when calling Claude to classify a ticket.
 
## Prompt
 
```
Classify this customer support ticket into exactly one category.
 
Categories: billing, shipping, returns, technical, account, feedback, other
 
Subject: {subject}
Body (first 500 chars): {body}
 
Reply with only the category name, 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 and lowercase it. If it doesn't match any category, use "other".
- To customize categories, update the list in this prompt and in the SKILL.md.

references/gorgias-tickets-api.md

Create .claude/skills/ticket-triage/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": 12345,
      "subject": "My order hasn't arrived yet",
      "status": "open",
      "tags": [],
      "messages": [
        {
          "id": 99001,
          "body_text": "Hi, I placed an order a week ago and haven't received it...",
          "source": { "type": "email" }
        }
      ]
    }
  ]
}
```
 
- Filter for tickets where `tags` is an empty array to find untagged tickets.
- The first message in `messages` is typically the customer's original message.
 
## Update a ticket (apply tag)
 
**Request:**
 
```
PUT /api/tickets/{ticket_id}
Content-Type: application/json
```
 
**IMPORTANT:** The `tags` field REPLACES the entire array. Fetch current tags first, add the new category tag, then PUT the merged list.
 
```json
{
  "tags": [
    { "name": "shipping" }
  ]
}
```

Step 4: Test the skill

Invoke the skill conversationally:

/ticket-triage

A typical run looks like:

Fetching untagged open tickets...
Found 15 untagged tickets
 
  #14401  "My order hasn't arrived yet"       →  shipping
  #14405  "Can I get a refund for this?"       →  returns
  #14408  "Error on checkout page"             →  technical
  #14412  "Update my billing address"          →  account
  #14415  "Love the new packaging!"            →  feedback
 
Tagged 15 ticket(s).

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

  • "What's the breakdown of ticket categories today?" — the agent classifies without tagging
  • "Add an 'urgent' tag alongside the topic tag for anything mentioning chargebacks" — the agent extends the logic
  • "Only classify tickets from the last 4 hours" — the agent adds a time filter
Start with 4-6 categories

Begin with broad categories (billing, shipping, returns, technical, account, feedback). You can always ask the agent to use more specific categories later without changing any files.

Step 5: Schedule it (optional)

Option A: Cron + Claude CLI

# Run every hour during business hours
0 8-18 * * 1-5 cd /path/to/your/project && claude -p "Run /ticket-triage" --allowedTools 'Bash(*)' 'Read(*)'

Option B: GitHub Actions + Claude

name: Ticket Triage
on:
  schedule:
    - cron: '0 13-22 * * 1-5'  # 8 AM-5 PM ET, weekdays
  workflow_dispatch: {}
jobs:
  triage:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: anthropics/claude-code-action@v1
        with:
          prompt: "Run /ticket-triage"
          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).

Claude classification vs. keyword Rules

Claude covers 90%+ of tickets accurately, including multilingual and conversational phrasing. Keyword Rules cover 70-80% but are faster and free. For best results, use Gorgias Rules to catch obvious keywords instantly and this skill to sweep up the remaining untagged tickets hourly.

Troubleshooting

When to use this approach

  • You need semantic classification — Claude understands "my parcel hasn't arrived" as shipping without the word "shipping"
  • You have multilingual customers and keyword Rules fail on non-English tickets
  • You want conversational flexibility — custom categories, analysis reports, time-filtered runs
  • You want to run tasks in the background via Claude Cowork while focusing on other work
  • You want to test categories before hardcoding them into Gorgias Rules

When to switch approaches

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

Common questions

How accurate is Claude at classifying tickets?

Very accurate for clear topics — 90%+ on well-defined categories. Edge cases like "I'm having trouble with my recent purchase" (could be returns, billing, or shipping) may need a secondary check. The fallback category "other" catches anything ambiguous.

Does this use Claude API credits?

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

Can I add urgency detection alongside topic classification?

Yes. Ask the agent conversationally: "Also tag tickets as 'urgent' if the message mentions chargebacks, legal, or broken." The agent will extend the classification logic in the generated script.

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.