| name | xnatctl |
| description | Use when running xnatctl commands, writing scripts that call xnatctl, troubleshooting XNAT CLI operations, or helping users with XNAT neuroimaging server administration via the command line. Triggers on mentions of xnatctl, XNAT CLI, session download/upload, prearchive, scan management, or XNAT project administration. |
xnatctl CLI Reference
Modern CLI for XNAT neuroimaging server administration. Resource-centric commands with consistent output formats, parallel operations, and profile-based configuration.
Command Hierarchy
xnatctl
config init | show | use-context | current-context | add-profile | remove-profile
auth login | logout | status | test
project list | show | create
subject list | show | rename | delete
session list | show | download | upload | upload-exam
scan list | show | delete | download
resource list | show | upload | download
prearchive list | archive | delete | rebuild | move
pipeline list | run | status | jobs | cancel
admin refresh-catalogs | user add | audit
dicom validate | inspect | list-tags | anonymize (requires xnatctl[dicom])
api get | post | put | delete (raw REST escape hatch)
whoami
health ping
completion [bash|zsh|fish]
Global Options (all commands)
| Flag | Short | Description |
|---|
--profile | -p | Named profile from config |
--output | -o | json or table (default: table) |
--quiet | -q | IDs only output |
--verbose | -v | Debug logging |
Parent-Resource Options (session & scan commands)
| Flag | Short | Purpose | Key Rule |
|---|
--project | -P | Project ID | Enables label lookup for -E |
--subject | -S | Subject ID/label | Used in session list (filter) and session upload |
--experiment | -E | Experiment ID or label | Labels require -P (explicit or via profile default_project) |
Critical: -E LABEL without -P fails. -E XNAT_E00001 (accession ID) works without -P.
Quick Reference: Common Commands
Setup & Auth
xnatctl config init --url https://xnat.example.org --profile myserver
xnatctl config add-profile prod --url https://prod.xnat.org --project DEFAULT_PROJ
xnatctl config use-context prod
xnatctl auth login -p myserver
xnatctl auth test
Projects & Subjects
xnatctl project list
xnatctl project show MYPROJ
xnatctl subject list -P MYPROJ --filter "label:CTRL_*"
xnatctl subject delete SUB001 -P MYPROJ --dry-run
xnatctl subject delete SUB001 -P MYPROJ --yes
Sessions
xnatctl session list -P MYPROJ
xnatctl session show -P MYPROJ -E MR_Session_01
xnatctl session show -E XNAT_E00001
xnatctl session download -P MYPROJ -E MR_Session_01 --out ./data
xnatctl session download -P MYPROJ -E MR_Session_01 --out ./data -w 8
Uploads
xnatctl session upload ./dicoms -P NEURO -S SUB001 -E SESS001 --workers 4
xnatctl session upload ./archive.tar -P NEURO -S SUB001 -E SESS001
xnatctl session upload ./dicoms -P NEURO -S SUB001 -E SESS001 --gradual --workers 16
xnatctl session upload-exam ./exam_root -P NEURO -S SUB001 -E SESS001 -w 4
xnatctl session upload-exam ./exam_root -P NEURO -S SUB001 -E SESS001 --attach-only
upload vs upload-exam: upload handles DICOM files only. upload-exam handles a mixed directory (DICOMs + non-DICOM resource files like PDFs, spreadsheets). In upload-exam, top-level directories become session-level resources by name.
Scans
xnatctl scan list -E XNAT_E00001
xnatctl scan delete -E XNAT_E00042 -P BRAIN -s 1,3,5 --dry-run
xnatctl scan delete -E XNAT_E00042 -P BRAIN -s 1,3,5 --yes
xnatctl scan delete -E XNAT_E00042 -s "*" --yes
xnatctl scan download -E XNAT_E00001 -s 1,2,3 --out ./scans
Resources
xnatctl resource list XNAT_E00001
xnatctl resource list XNAT_E00001 --scan 1
xnatctl resource upload XNAT_E00001 MY_RESOURCE ./data/
xnatctl resource download XNAT_E00001 MY_RESOURCE --file ./output.zip
Prearchive
Note: Prearchive commands use POSITIONAL args: PROJECT TIMESTAMP SESSION_NAME
xnatctl prearchive list
xnatctl prearchive list --project MYPROJ
xnatctl prearchive archive MYPROJ 20240115_143022 SessionFolder
xnatctl prearchive delete MYPROJ 20240115_143022 SessionFolder --yes
xnatctl prearchive rebuild MYPROJ 20240115_143022 SessionFolder
xnatctl prearchive move MYPROJ 20240115_143022 SessionFolder TARGET_PROJ
Pipelines
xnatctl pipeline list --project MYPROJ
xnatctl pipeline run dcm2niix -e XNAT_E00001 -P key1=val1 -P key2=val2 --wait
xnatctl pipeline status JOB_ID --watch
xnatctl pipeline cancel JOB_ID --yes
Admin
xnatctl admin refresh-catalogs MYPROJ -O checksum -O populateStats --parallel --workers 8
xnatctl admin user add jsmith Owners --projects MYPROJ
xnatctl admin audit -P MYPROJ --since 7d --limit 50
Raw API (escape hatch)
xnatctl api get /data/projects/MYPROJ/subjects -P format=json
xnatctl api post /data/projects -d '{"ID":"NEW_PROJ","name":"New Project"}'
xnatctl api delete /data/experiments/XNAT_E00001 --yes
DICOM Tools (requires xnatctl[dicom])
xnatctl dicom validate ./dicoms -r
xnatctl dicom inspect ./scan.dcm -t PatientID -t Modality
xnatctl dicom anonymize ./input ./output --patient-id ANON001 --remove-private -r
Configuration
Config file: ~/.config/xnatctl/config.yaml
default_profile: default
output_format: table
profiles:
default:
url: https://xnat.example.org
verify_ssl: true
timeout: 21600
default_project: MYPROJ
username: admin
password: secret
Environment variables (priority: CLI args > env vars > profile > prompt):
| Variable | Purpose |
|---|
XNAT_TOKEN | Session token (highest auth priority, skips credential prompt) |
XNAT_URL | Server URL (auto-creates default profile) |
XNAT_USER | Username |
XNAT_PASS | Password |
XNAT_PROFILE | Active profile |
XNAT_VERIFY_SSL | true/false |
XNAT_TIMEOUT | Timeout seconds |
Gotchas
-o is output FORMAT (json/table), NOT output directory. Use --out for download destination.
- Filter uses colon:
--filter "label:CTRL_*" not label=CTRL_*.
- Scan IDs use
-s flag: -s 1,3,5 (comma-separated) or -s "*" (all). NOT positional args.
- Prearchive uses positional args:
PROJECT TIMESTAMP SESSION_NAME. NOT -P/-E flags.
- API params use
-P key=value: NOT query strings appended to path.
- Workers flag varies: session download uses
-w, upload uses --workers. Both control parallelism.
-P flag is overloaded: In session/scan commands, -P means --project. In api and pipeline commands, -P means parameter (key=value). Context matters.
- Default timeout is 6 hours (21600s) for large DICOM transfers.
- upload-exam waits for archive: By default waits for XNAT to finish archiving before attaching resources. Control with
--wait-for-archive/--no-wait-for-archive.
default_project fallback: If profile has default_project, -P can be omitted and session/scan commands auto-resolve.
Safety Decorators
Destructive commands include --yes/-y (skip confirmation) and --dry-run (preview only). Always use --dry-run first for delete/rename operations.
Parallel commands include --parallel/--no-parallel and --workers N.