A Xircuits component library for integrating with Claude Code CLI, enabling scripted automation of Claude Code commands with cost and edit tracking.
Executes Claude Code CLI commands and captures output, errors, and execution metrics.
Input Ports:
command
: The claude command to execute (e.g., "chat", "help")args
: Additional arguments for the commandinput_text
: Text input to provide to the commandworking_dir
: Working directory for command executiontimeout
: Command timeout in seconds
Output Ports:
output
: Command stdouterror
: Command stderrreturn_code
: Exit codeexecution_time
: Execution time in seconds
Analyzes Claude Code output to extract usage statistics and edit information.
Input Ports:
output
: stdout from Claude Code commanderror
: stderr from Claude Code command
Output Ports:
input_tokens
: Number of input tokens usedoutput_tokens
: Number of output tokens usedtotal_cost
: Total cost in USDfiles_edited
: List of edited filesedit_summary
: Summary of edits madehas_errors
: Boolean indicating errorssuccess
: Boolean indicating success
Convenient wrapper for Claude Code chat commands.
Input Ports:
prompt
: The prompt to send to Claudemodel
: Optional model specificationworking_dir
: Working directory
Output Ports:
response
: Claude's responsetokens_used
: Total tokens usedcost
: Cost of interactionsuccess
: Success indicator
Executes file editing commands with Claude Code.
Input Ports:
file_path
: Path to file to editinstruction
: Edit instructionmodel
: Optional model
Output Ports:
success
: Edit success indicatorchanges_made
: Description of changestokens_used
: Tokens consumedcost
: Operation cost
Executes multiple Claude Code commands in sequence with aggregated results.
Input Ports:
commands
: List of command stringsworking_dir
: Working directory
Output Ports:
results
: List of individual resultstotal_tokens
: Aggregated token usagetotal_cost
: Total costsuccess_count
: Number of successful operationsfailed_count
: Number of failed operations
Generates usage summaries from Claude Code operation results.
Input Ports:
results
: List of operation results
Output Ports:
summary
: Text summarytotal_operations
: Operation countsuccessful_operations
: Success counttotal_tokens
: Total tokenstotal_cost
: Total costaverage_cost_per_operation
: Average cost per operation
pip install -r requirements.txt
- Claude Code CLI must be installed and configured
- xai-components must be installed
- Valid Claude API credentials configured
Create a workflow with:
ClaudeCodeChat
component with prompt "Explain Python decorators"ClaudeCodeAnalyze
component to extract cost information- Output the response and cost data
ClaudeCodeFileEdit
- Edit a specific fileClaudeCodeAnalyze
- Extract edit and cost information- Log or display the results
ClaudeCodeBatch
- Execute multiple commandsClaudeCodeUsageSummary
- Generate usage report- Output aggregated statistics
ClaudeCodeExecute
- Run any Claude Code commandClaudeCodeAnalyze
- Parse the results- Process the extracted data
The components rely on the Claude Code CLI being properly configured with:
- Valid API credentials
- Appropriate model access
- Proper authentication setup
Refer to the Claude Code documentation for setup instructions.
All components include error handling for:
- Command timeouts
- Invalid commands
- Network issues
- Authentication failures
Error information is captured in the respective output ports.
The components automatically extract and track:
- Token usage (input/output)
- Operation costs
- Usage summaries
- Per-operation metrics
This enables effective monitoring and budgeting of Claude Code usage in automated workflows.