Automating YouTrack Issue Creation from Claude Code

By | November 24, 2026

When an AI coding assistant uncovers a bug or architectural issue mid-session, copying context into an issue tracker by hand breaks your flow. With a small Python wrapper around the YouTrack REST API, Claude Code can draft, dry-run, and file structured YouTrack issues in one command.

The Architecture

The integration relies on four clean pieces:

Component Location Purpose
CLI Script ~/scripts/youtrack_issue.py Creates an issue via the YouTrack REST API and prints its ID and URL.
API Token ~/.config/youtrack/token Permanent YouTrack token (mode 600, folder mode 700).
Memory Rule Meta/claude-memory.md Instructs Claude to use this workflow when asked to file an issue.
Infra Fact Meta/claude-memory.md Stores the API endpoint, project IDs, and token path.

Security note: Keep the token strictly in ~/.config/youtrack/token—never inside your Obsidian vault, where automated memory dreams or backups could copy it. The script never prints the token.

The Issue-Filing Procedure

  1. Draft the issue in ASD-STE100 (Simplified Technical English) as a Markdown file with five clear sections:
    • Title: One line describing what is wrong.
    • Problem: What the code does, with file:line references.
    • Impact: What fails and when.
    • Proposed fix: The exact change needed.
    • Acceptance: The checks that prove the fix works.
  2. Dry-run the request without creating anything:
    python3 ~/scripts/youtrack_issue.py --summary "<title>" --body-file issue.md --dry-run
  3. Create the issue:
    python3 ~/scripts/youtrack_issue.py --summary "<title>" --body-file issue.md

    The script prints the readable ID and URL, for example: PROJ-405 https://example.youtrack.cloud/issue/PROJ-405.

Useful options include --project <short name> to target a specific project, or omitting --body-file to pipe the description from stdin.

How the Script Works Under the Hood

  1. Reads the permanent token from ~/.config/youtrack/token.
  2. Resolves the internal project ID from the short name via GET /api/admin/projects?fields=id,shortName (e.g., 0-101).
  3. Creates the issue via POST /api/issues?fields=idReadable with Authorization: Bearer <token> and a JSON body containing project, summary, and description (rendered as Markdown by YouTrack).
  4. Fails fast with the HTTP status and error text if any call fails.

By default, the script leaves custom fields (type, priority, assignee) unset so you can triage them in YouTrack—or extend the payload with "customFields" if needed.

Safe Token Rotation

To rotate the permanent token without ever exposing it in your shell history or on screen:

install -m 600 /dev/null ~/.config/youtrack/token && read -rs T && printf '%s' "$T" > ~/.config/youtrack/token && unset T

Then verify it with a dry-run (python3 ~/scripts/youtrack_issue.py --summary test --dry-run < /dev/null) before revoking the old token in YouTrack.

The Script (~/scripts/youtrack_issue.py)

#!/usr/bin/env python3
"""Create a YouTrack issue on example.youtrack.cloud.

Usage:
  youtrack_issue.py --summary "Title" [--project PROJ] [--body-file issue.md | < issue.md] [--dry-run]

The description is Markdown (from --body-file, or stdin). The token is read from ~/.config/youtrack/token
(mode 600); it is never printed. The project is given by its short name (PROJ = my-project) and resolved to its
internal id through the API. Prints the new issue id and its URL.
"""
import argparse
import json
import pathlib
import sys
import urllib.error
import urllib.parse
import urllib.request

BASE = "https://example.youtrack.cloud"
TOKEN_FILE = pathlib.Path.home() / ".config" / "youtrack" / "token"


def call(method, path, token, payload=None):
    req = urllib.request.Request(
        BASE + path,
        data=None if payload is None else json.dumps(payload).encode(),
        headers={"Authorization": "Bearer " + token, "Accept": "application/json",
                 "Content-Type": "application/json"},
        method=method)
    try:
        with urllib.request.urlopen(req, timeout=30) as r:
            return json.load(r)
    except urllib.error.HTTPError as e:
        sys.exit(f"YouTrack {method} {path} failed: HTTP {e.code} {e.read()[:500].decode(errors='replace')}")


def project_id(short_name, token):
    query = urllib.parse.urlencode({"fields": "id,shortName", "$top": "500"})
    for p in call("GET", "/api/admin/projects?" + query, token):
        if p.get("shortName") == short_name:
            return p["id"]
    sys.exit(f"No YouTrack project with short name {short_name}")


def main():
    ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
    ap.add_argument("--summary", required=True)
    ap.add_argument("--project", default="PROJ", help="project short name (default PROJ = my-project)")
    ap.add_argument("--body-file", help="Markdown description file (default: stdin)")
    ap.add_argument("--dry-run", action="store_true", help="print the request, create nothing")
    args = ap.parse_args()

    body = pathlib.Path(args.body_file).read_text() if args.body_file else sys.stdin.read()
    if not TOKEN_FILE.exists():
        sys.exit(f"Token file {TOKEN_FILE} is missing")
    token = TOKEN_FILE.read_text().strip()

    payload = {"project": {"id": project_id(args.project, token)}, "summary": args.summary, "description": body}
    if args.dry_run:
        print(json.dumps({**payload, "description": body[:300] + ("..." if len(body) > 300 else "")}, indent=2))
        return
    issue = call("POST", "/api/issues?fields=idReadable", token, payload)
    print(f"{issue['idReadable']} {BASE}/issue/{issue['idReadable']}")


if __name__ == "__main__":
    main()

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.