{"slug": "hack-claude-p", "title": "Hack: claude -p", "summary": "A developer shares a quick hack using the `claude -p` command-line tool to call Anthropic's Claude API without separate key management, leveraging the existing authenticated Claude environment. The script, which classifies GitHub pull requests, uses a subprocess call to `claude -p` with a prompt and returns JSON output, simplifying LLM integration in work contexts.", "body_md": "# Hack: claude -p\n\n`claude -p`\n\nis a quick hack that I find myself using more.\n\nCalling one of the various LLM APIs is easy. But requires key management. For me on a personal project that’s no big deal. In a work context it’s less trivial. But I’m working in `claude`\n\n, which means I have a tool talking to a LLM API running already all the time, that already has not only an API key, but also an allocated budget that is being managed around making me more productive. Much easier if all my LLM based productivity is spend hits a single line item.\n\nE.g. a quick script to classify Github PRs has a section like:\n\n```\n  return f\"\"\"You are classifying GitHub pull requests for an engineering team.\n\n  PRODUCT AREAS (choose exactly one per PR):\n  {area_lines}\n\n  WORK TYPES (choose exactly one per PR):\n  {work_type_lines}\n\n  For each PR, return a JSON array with these fields:\n  - pr_id, product_area, work_type, confidence, keywords\n\n  Return ONLY the JSON array. No prose, no markdown fences.\n\n  PULL REQUESTS:\n  {prs_text}\"\"\"\n```\n\nAnd the call itself:\n\n``` php\n  def _call_claude(prompt: str) -> str | None:\n      try:\n          result = subprocess.run(\n              ['claude', '-p', '--output-format', 'text'],\n              input=prompt,\n              capture_output=True,\n              text=True,\n              timeout=300,\n          )\n          return result.stdout.strip() if result.returncode == 0 else None\n      except (subprocess.TimeoutExpired, FileNotFoundError):\n          return None\n```\n\nProbably this is what the agent sdk is for? This worked.", "url": "https://wpnews.pro/news/hack-claude-p", "canonical_source": "https://laughingmeme.org/2026/03/20/hack-claude-p.html", "published_at": "2026-08-17 10:21:17+00:00", "updated_at": "2026-08-17 10:41:27.072345+00:00", "lang": "en", "topics": ["developer-tools", "artificial-intelligence", "large-language-models"], "entities": ["Anthropic", "Claude", "GitHub"], "alternates": {"html": "https://wpnews.pro/news/hack-claude-p", "markdown": "https://wpnews.pro/news/hack-claude-p.md", "text": "https://wpnews.pro/news/hack-claude-p.txt", "jsonld": "https://wpnews.pro/news/hack-claude-p.jsonld"}}