Credential Check
Before using this skill, verify credentials are configured:
source .env && echo "QB URL: $QB_URL" && echo "User: $QB_USER"
If this shows nothing or errors, guide the user through First-Time Setup below.
Environment Setup
Credentials are stored in .env (gitignored):
QB_URL=http://localhost:8080
QB_USER=admin
QB_PASS=your-password
Torrent Sources (Vanilla)
The tracked, portable template is .opencode/skill/qbittorrent/torrent-sources.example.json.
During setup, copy it to .opencode/skill/qbittorrent/torrent-sources.json (gitignored) and customize it for your environment:
cp .opencode/skill/qbittorrent/torrent-sources.example.json .opencode/skill/qbittorrent/torrent-sources.json
List the configured sources:
jq -r '.sources[] | "\(.name)\t\(.url)\(.searchPath)"' .opencode/skill/qbittorrent/torrent-sources.json
Quick Usage
End-to-end flow
- Pick a source from
.opencode/skill/qbittorrent/torrent-sources.json(create it from the example if missing) and grab a magnet link or.torrentfile from the official page. - Login to the Web API (stores a
SIDcookie in/tmp/qb.txt). - Add the torrent (magnet or
.torrent). - Monitor progress/state until complete.
Login and store session
source .env && curl -s -c /tmp/qb.txt -b /tmp/qb.txt \
"$QB_URL/api/v2/auth/login" \
-d "username=$QB_USER&password=$QB_PASS"
Add a magnet link
# IMPORTANT: Must use -F (multipart/form-data), NOT -d!
curl -s -c /tmp/qb.txt -b /tmp/qb.txt \
"$QB_URL/api/v2/torrents/add" \
-F "urls=magnet:?xt=urn:btih:HASH&dn=NAME"
Add a .torrent file
curl -s -c /tmp/qb.txt -b /tmp/qb.txt \
"$QB_URL/api/v2/torrents/add" \
-F "torrents=@/path/to/file.torrent"
Response meanings:
Ok.= Successfully addedFails.= Torrent already exists (duplicate) - NOT an error!
Add with save path and category
curl -s -c /tmp/qb.txt -b /tmp/qb.txt \
"$QB_URL/api/v2/torrents/add" \
-F "urls=MAGNET_LINK" \
-F "savepath=/downloads/movies" \
-F "category=movies"
List all torrents
curl -s -b /tmp/qb.txt "$QB_URL/api/v2/torrents/info"
Check torrent status by hash
curl -s -b /tmp/qb.txt "$QB_URL/api/v2/torrents/info?hashes=HASH_LOWERCASE"
Latest torrent + completion
curl -s -b /tmp/qb.txt "$QB_URL/api/v2/torrents/info" | jq -r '
if length==0 then "No torrents"
else (sort_by(.added_on) | last) as $t
| "name=\($t.name)\nhash=\($t.hash)\nstate=\($t.state)\nprogress=\($t.progress)\nadded_on=\($t.added_on)\ncompletion_on=\($t.completion_on)\nsave_path=\($t.save_path)"
end'
Rule of thumb: a torrent is finished when progress is 1 and state is uploading/stoppedUP/pausedUP.
One-liner: Login and add torrent
source .env && \
curl -s -c /tmp/qb.txt "$QB_URL/api/v2/auth/login" -d "username=$QB_USER&password=$QB_PASS" && \
curl -s -b /tmp/qb.txt "$QB_URL/api/v2/torrents/add" -F "urls=MAGNET_LINK_HERE"
Torrent States
| State | Meaning |
|---|---|
downloading | Currently downloading |
stoppedDL | Paused while downloading |
uploading | Currently seeding |
stoppedUP | Completed, seeding stopped |
stalledDL | No peers available |
error | Error occurred |
Common Gotchas
- Must use
-Fnot-dfor adding torrents (multipart/form-data required) Fails.response = duplicate torrent, not an error- Some endpoints (including
/api/v2/app/version) may return403 Forbiddenuntil you authenticate and send theSIDcookie - Session cookie stored in
/tmp/qb.txt- re-login if expired - Hash must be lowercase when querying
Manage Torrents
Pause torrent
curl -s -b /tmp/qb.txt -X POST "$QB_URL/api/v2/torrents/pause" \
-d "hashes=HASH"
Resume torrent
curl -s -b /tmp/qb.txt -X POST "$QB_URL/api/v2/torrents/resume" \
-d "hashes=HASH"
Delete torrent (keep files)
curl -s -b /tmp/qb.txt -X POST "$QB_URL/api/v2/torrents/delete" \
-d "hashes=HASH&deleteFiles=false"
Delete torrent and files
curl -s -b /tmp/qb.txt -X POST "$QB_URL/api/v2/torrents/delete" \
-d "hashes=HASH&deleteFiles=true"
First-Time Setup (If Credentials Missing)
What you need from the user
- Web UI URL - Default is
http://localhost:8080 - Username - Default is
admin - Password - Set in qBittorrent preferences
- Torrent sources config - Copy the example to a local config (gitignored)
cp .opencode/skill/qbittorrent/torrent-sources.example.json .opencode/skill/qbittorrent/torrent-sources.json
Step 1: Enable Web UI in qBittorrent
Tell the user:
- Open qBittorrent
- Go to Tools > Options > Web UI
- Check "Web User Interface (Remote control)"
- Set port (default 8080)
- Set username and password
- Click OK
Step 2: Add credentials to .env
cat >> .env << 'EOF'
# qBittorrent
QB_URL=http://localhost:8080
QB_USER=admin
QB_PASS=your-password-here
EOF
Step 3: Test it works
source .env && \
curl -s -c /tmp/qb.txt "$QB_URL/api/v2/auth/login" -d "username=$QB_USER&password=$QB_PASS" >/dev/null && \
curl -s -b /tmp/qb.txt "$QB_URL/api/v2/app/version"
# Should return version like "v5.1.2" (some setups return 403 until authenticated)
API Reference
| Endpoint | Method | Description |
|---|---|---|
/api/v2/auth/login | POST | Login (username, password) |
/api/v2/torrents/add | POST | Add torrent (-F urls=magnet) |
/api/v2/torrents/info | GET | List all torrents |
/api/v2/torrents/info?hashes=X | GET | Get specific torrent |
/api/v2/torrents/pause | POST | Pause (hashes=X) |
/api/v2/torrents/resume | POST | Resume (hashes=X) |
/api/v2/torrents/delete | POST | Delete (hashes=X, deleteFiles=bool) |
/api/v2/app/version | GET | Get qBittorrent version |
