A Python Flask web application that integrates with the Claude Code SDK, providing a web interface for interacting with Claude Code programmatically.
- Web Interface: User-friendly form for submitting prompts to Claude Code
- Async Processing: Handles Claude Code SDK async operations with anyio
- Session Management: Track and view conversation sessions
- API Endpoint: RESTful API for programmatic access
- Error Handling: Comprehensive error handling and user feedback
- Responsive Design: Mobile-friendly interface
- Python 3.10+
- Node.js (required by Claude Code SDK)
- Claude Code CLI:
npm install -g @anthropic-ai/claude-code - Anthropic API key
-
Clone and navigate to the project:
cd agents-in-the-loop -
Install Python dependencies:
pip install -r requirements.txt
Install the browser:
playwright install chromium --with-deps --no-shell
-
Set up environment variables:
- Copy
.envfile and add your Anthropic API key:
ANTHROPIC_API_KEY=your_api_key_here
- Copy
-
Run the application:
python app.py
-
Open your browser: Navigate to
http://localhost:5000
- Open
http://localhost:5000in your browser - Enter your coding prompt in the text area
- Select the maximum number of turns for the conversation
- Click "Submit Query" to process your request
- View the results with full conversation history
Send POST requests to /api/query:
curl -X POST http://localhost:5000/api/query \
-H "Content-Type: application/json" \
-d '{
"prompt": "Write a Python function to calculate Fibonacci numbers",
"max_turns": 3
}'- "Write a Python function to calculate Fibonacci numbers"
- "Review this code for bugs and suggest improvements"
- "Create a REST API endpoint for user authentication"
- "Add unit tests for the calculator module"
agents-in-the-loop/
├── app.py # Main Flask application
├── requirements.txt # Python dependencies
├── .env # Environment variables
├── README.md # This file
├── templates/
│ ├── index.html # Main interface
│ └── result.html # Results display
└── static/
└── style.css # Styling
GET /- Main web interfacePOST /query- Process Claude Code queries (web form)GET /session/<session_id>- View session resultsPOST /api/query- API endpoint for programmatic accessGET /health- Health check endpoint
The application supports various configuration options through environment variables:
ANTHROPIC_API_KEY- Your Anthropic API key (required)FLASK_ENV- Flask environment (development/production)FLASK_DEBUG- Enable debug modeSECRET_KEY- Flask secret key for sessionsCLAUDE_CODE_USE_BEDROCK=1- Use Amazon Bedrock (optional)CLAUDE_CODE_USE_VERTEX=1- Use Google Vertex AI (optional)
The application includes comprehensive error handling:
- Input validation for required fields
- Claude Code SDK error handling
- HTTP error responses (404, 500)
- User-friendly error messages in the web interface
- Never commit API keys to version control
- Use environment variables for sensitive configuration
- Implement rate limiting in production
- Consider authentication for production deployments
To extend the application:
- Add new routes in
app.py - Modify templates in the
templates/directory - Update styling in
static/style.css - Add dependencies to
requirements.txt
- "ANTHROPIC_API_KEY not set": Ensure your API key is configured in
.env - Claude Code SDK errors: Verify Node.js and Claude Code CLI are installed
- Import errors: Run
pip install -r requirements.txt - Port conflicts: Change the port in
app.pyif 5000 is in use
This project is for educational and development purposes.