I wanted my AI coding agent to shorten links for me. Not by opening a browser or switching tabs — by just telling it “shorten this” and getting a tracked short link back. So I built an API for gofwd.to
and wired it up to Claude Code. Now I type /shorten https://some-long-url.com and I’m done.
Here’s how to set up the same thing for yourself.
The Idea: AI Agent + URL Shortener API
The concept is simple. You give your AI coding agent (Claude Code, Cursor, Windsurf, whatever you use) a skill or command that calls a URL shortener API. The agent runs a single curl request, parses the response, and hands you back a short link. No tab switching, no copy-paste dance.
But this isn’t just an AI agent trick. The same API works for anything that can make an HTTP request:
- Slack bots that auto-shorten links in messages
- CI pipelines that generate short links for deploy previews
- Marketing scripts that batch-create campaign links
- Any automation where you need a tracked short link programmatically
You need two things: a URL shortener with an API, and about five minutes. gofwd.to has an API with click tracking built in — plans start at $2/year — so that’s what we’ll use.
Get Your API Key
This takes thirty seconds.
- Sign up at gofwd.to (or sign in if you already have an account)
- Go to API Keys
- Create a key, give it a name, and copy it
You’ll see the full key once — it starts with gofwd_. Store it somewhere safe.
Set it as an environment variable so your tools can use it:
export GOFWDTO_API_KEY=gofwd_your_key_hereAdd that line to your ~/.zshrc or ~/.bashrc to persist it across sessions.
Shorten Your First Link
One request, one tracked short link:
curl -s -X POST https://api.gofwd.to/v1/links \
-H "Authorization: Bearer $GOFWDTO_API_KEY" \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com/some/very/long/path"}'Response:
{
"id": "abc123",
"url": "https://example.com/some/very/long/path",
"short_url": "https://gofwd.to/abc123",
"expires_at": "2027-02-20T12:00:00Z"
}That’s it. short_url is your tracked link. Every click on it shows up in your gofwd.to dashboard
with analytics. Links expire after one year.
Wire It Up to Claude Code
Here’s where it gets good. Claude Code supports custom skills — slash commands that run predefined workflows. You can create a /shorten skill that calls the API for you.
Create a file at .claude/skills/shorten/SKILL.md in your project (or ~/.claude/skills/shorten/SKILL.md for global access):
---
name: shorten
description: Shorten a URL using the gofwd.to API
allowed-tools: Bash(curl *)
---
# Shorten URL
Shorten the given URL using the gofwd.to URL shortener API.
**URL to shorten:** $ARGUMENTS
## Pre-check
First, verify that `GOFWDTO_API_KEY` is set by running
`[ -n "$GOFWDTO_API_KEY" ] && echo "set" || echo "not set"`.
If not set, tell the user to set it with
`export GOFWDTO_API_KEY=gofwd_your_key_here`.
Stop and do not proceed until the key is set.
## Instructions
1. Call the gofwd.to API:
```bash
curl -s -X POST https://api.gofwd.to/v1/links \
-H "Authorization: Bearer $GOFWDTO_API_KEY" \
-H "Content-Type: application/json" \
-d '{"url": "<THE_URL>"}'- Read the JSON response and extract the
short_urlfield - Return ONLY the shortened URL to the user
Now you type `/shorten https://example.com/long-url` in Claude Code and get back `https://gofwd.to/abc123`. That's the AI agent angle in practice — one command, no context switch, tracked link in your clipboard.
## The Full API
Three endpoints, all authenticated with your API key.
### Create a Link
```bash
curl -s -X POST https://api.gofwd.to/v1/links \
-H "Authorization: Bearer $GOFWDTO_API_KEY" \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com"}'Pro users can set a custom short code:
curl -s -X POST https://api.gofwd.to/v1/links \
-H "Authorization: Bearer $GOFWDTO_API_KEY" \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com", "custom_code": "my-link"}'List Your Links
curl -s https://api.gofwd.to/v1/links \
-H "Authorization: Bearer $GOFWDTO_API_KEY"Returns all your links with creation and expiration dates:
{
"links": [
{
"id": "abc123",
"url": "https://example.com",
"short_url": "https://gofwd.to/abc123",
"created_at": "2026-02-20T10:30:45Z",
"expires_at": "2027-02-20T10:30:45Z"
}
]
}Delete a Link
curl -s -X DELETE https://api.gofwd.to/v1/links/abc123 \
-H "Authorization: Bearer $GOFWDTO_API_KEY"Returns {"message": "Link deleted"} on success.
Code Examples
JavaScript (fetch)
async function shortenLink(url) {
const res = await fetch("https://api.gofwd.to/v1/links", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.GOFWDTO_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ url }),
});
const data = await res.json();
if (!res.ok) throw new Error(data.error);
return data.short_url;
}
// Usage
const shortUrl = await shortenLink("https://example.com/long-path");
console.log(shortUrl); // https://gofwd.to/abc123
Python (requests)
import os
import requests
def shorten_link(url):
res = requests.post(
"https://api.gofwd.to/v1/links",
headers={
"Authorization": f"Bearer {os.environ['GOFWDTO_API_KEY']}",
"Content-Type": "application/json",
},
json={"url": url},
)
res.raise_for_status()
return res.json()["short_url"]
# Usage
short_url = shorten_link("https://example.com/long-path")
print(short_url) # https://gofwd.to/abc123Error Handling
The API returns standard HTTP status codes with a JSON error field:
| Status | Meaning | What to Do |
|---|---|---|
401 | Invalid or missing API key | Check your Authorization header and key |
402 | Monthly link limit reached (Starter plan: 25/month) | Upgrade to Pro for unlimited links |
403 | Custom codes require Pro | Either drop the custom_code field or upgrade |
400 | Bad request (missing URL, invalid input) | Check your request body |
Go Shorten Some Links
That’s the whole thing. Get an API key, make a POST request, get a tracked short link. Wire it up to your AI agent, your scripts, your bots — whatever needs to create short links programmatically.
Sign up at gofwd.to and grab your API key from Settings → API Keys . The Starter plan is $2/year and gives you 25 links per month with full click analytics.

