Félix's Blog

Using Claude Code programmatically

There are some one-off tasks that can't be easily generalized to a proper agent but that are still so tedious that I want to automate them.

Creating an agent with Claude Code SDK or Microsoft Agent Framework is nice but takes time. It turns out Claude Code by itself is a solid agent and I don't have to pay anything beyond $200/mo.

claude -p \ # print mode, non-interactive
 --output-format json \
 --json-schema '{"type":"object"...}'
 --allowedTools "WebSearch,WebFetch,Grep,Glob,Read"
 --dangerously-skip-permissions
 --system-prompt "Validate me."
 "Prompt here."

It has a nice response structure:

{
  "type": "result",
  "subtype": "success",
  "is_error": false,
  "duration_ms": 5237,
  "num_turns": 2,
  "result": "",                    
  "structured_output": {          
     "yourData": "isHere"
  },
  "session_id": "...",
  "total_cost_usd": 0.099
}

I can then create a small wrapper script that calls this in parallel.