{"id":50767674,"url":"https://github.com/arktnld/claude-code-api","last_synced_at":"2026-06-11T15:02:18.568Z","repository":{"id":359142898,"uuid":"1244745794","full_name":"arktnld/claude-code-api","owner":"arktnld","description":"REST API wrapper for Claude Code CLI — execute code, manage files, and run commands remotely. Built on claude-agent-sdk with FastAPI.","archived":false,"fork":false,"pushed_at":"2026-05-20T16:30:22.000Z","size":117,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-20T19:52:43.438Z","etag":null,"topics":["ai","ai-agents","anthropic","automation","claude","claude-api","claude-code","claude-sdk","code-generation","developer-tools","fastapi","llm","python","rest-api"],"latest_commit_sha":null,"homepage":"https://github.com/arktnld/claude-code-api/wiki","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arktnld.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"docs/security.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-20T14:56:35.000Z","updated_at":"2026-05-20T16:30:29.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/arktnld/claude-code-api","commit_stats":null,"previous_names":["arktnld/claude-code-api"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/arktnld/claude-code-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arktnld%2Fclaude-code-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arktnld%2Fclaude-code-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arktnld%2Fclaude-code-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arktnld%2Fclaude-code-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arktnld","download_url":"https://codeload.github.com/arktnld/claude-code-api/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arktnld%2Fclaude-code-api/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34204199,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-11T02:00:06.485Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","ai-agents","anthropic","automation","claude","claude-api","claude-code","claude-sdk","code-generation","developer-tools","fastapi","llm","python","rest-api"],"created_at":"2026-06-11T15:02:17.756Z","updated_at":"2026-06-11T15:02:18.539Z","avatar_url":"https://github.com/arktnld.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003ch1 align=\"center\"\u003eClaude Code API\u003c/h1\u003e\n  \u003cp align=\"center\"\u003e\n    REST API wrapper for Claude Code CLI — execute code, manage files, and run commands remotely.\n  \u003c/p\u003e\n  \u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/arktnld/claude-code-api/releases\"\u003e\u003cimg src=\"https://img.shields.io/github/v/release/arktnld/claude-code-api?style=flat-square\u0026color=blue\" alt=\"Release\"\u003e\u003c/a\u003e\n    \u003ca href=\"LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/github/license/arktnld/claude-code-api?style=flat-square\" alt=\"License\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://www.python.org/\"\u003e\u003cimg src=\"https://img.shields.io/badge/python-3.11+-blue?style=flat-square\u0026logo=python\u0026logoColor=white\" alt=\"Python\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://fastapi.tiangolo.com/\"\u003e\u003cimg src=\"https://img.shields.io/badge/FastAPI-0.115+-009688?style=flat-square\u0026logo=fastapi\u0026logoColor=white\" alt=\"FastAPI\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/arktnld/claude-code-api/stargazers\"\u003e\u003cimg src=\"https://img.shields.io/github/stars/arktnld/claude-code-api?style=flat-square\" alt=\"Stars\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/arktnld/claude-code-api/issues\"\u003e\u003cimg src=\"https://img.shields.io/github/issues/arktnld/claude-code-api?style=flat-square\" alt=\"Issues\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/arktnld/claude-code-api/wiki\"\u003e\u003cimg src=\"https://img.shields.io/badge/docs-wiki-orange?style=flat-square\" alt=\"Wiki\"\u003e\u003c/a\u003e\n  \u003c/p\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"#features\"\u003eFeatures\u003c/a\u003e •\n  \u003ca href=\"#quick-start\"\u003eQuick Start\u003c/a\u003e •\n  \u003ca href=\"#api-overview\"\u003eAPI Overview\u003c/a\u003e •\n  \u003ca href=\"https://github.com/arktnld/claude-code-api/wiki\"\u003eWiki\u003c/a\u003e •\n  \u003ca href=\"docs/\"\u003eDocs\u003c/a\u003e •\n  \u003ca href=\"#configuration\"\u003eConfiguration\u003c/a\u003e •\n  \u003ca href=\"#docker\"\u003eDocker\u003c/a\u003e\n\u003c/p\u003e\n\n---\n\n## About\n\n**Claude Code API** exposes Claude Code's full capabilities through a REST API. Built on [`claude-agent-sdk`](https://github.com/anthropics/claude-code-sdk-python), it spawns the real Claude Code CLI with access to all native tools — Read, Write, Edit, Bash, Glob, Grep, and more.\n\n\u003e [!IMPORTANT]\n\u003e This is an **educational/study project**. It is not affiliated with or endorsed by Anthropic. Use at your own risk. See [Disclaimer](#disclaimer).\n\n### Why this project?\n\nIf you already have **Claude Code CLI** installed and logged in on your machine (`claude auth login`), this API turns it into a **remote-accessible service** — no Anthropic API key needed, no extra billing. Your existing **Max or Pro plan** powers every request.\n\n| | Traditional API | Claude Code API |\n|---|---|---|\n| **Authentication** | Requires `ANTHROPIC_API_KEY` | Works with your existing CLI login |\n| **Billing** | Pay per API token | Uses your Max/Pro plan — already paid |\n| **Tools** | Text-only LLM responses | Full tool access: Read, Write, Edit, Bash, Glob, Grep |\n| **Capabilities** | Chat completion | Executes real code, creates files, runs commands |\n| **Context** | Stateless | Persistent sessions with auto-resume |\n| **Setup** | Get API key, configure SDK | `claude auth login` → done |\n\n\u003e **TL;DR:** Already paying for Claude Max? This gives you a REST API on top of it — for free.\n\n## Features\n\n| Feature | Description |\n|---------|-------------|\n| **Full Claude Code access** | All CLI tools: Read, Write, Edit, Bash, Glob, Grep, LS, MultiEdit |\n| **Session management** | Named sessions with auto-resume, templates, and lifecycle tracking |\n| **Sync \u0026 Stream chat** | Synchronous responses or real-time SSE streaming |\n| **Async jobs** | Fire-and-forget with webhook callbacks and cancellation |\n| **File management** | Upload, download, and list files in session workspaces |\n| **Agent templates** | 12 pre-configured profiles (code-reviewer, debug, devops, etc.) — customizable via YAML |\n| **Security** | API key auth, rate limiting, path sandboxing, input moderation, budget caps |\n| **RFC 9457 errors** | Structured Problem Details on every error response |\n| **Swagger UI** | Interactive docs at `/docs` with categorized endpoints |\n| **Usage \u0026 audit** | Cost tracking, usage stats, and full audit trail |\n| **Docker ready** | Production Dockerfile with gunicorn + uvicorn workers |\n\n## Quick Start\n\n### Prerequisites\n\n- Python 3.11+\n- [Claude Code CLI](https://docs.anthropic.com/en/docs/claude-code) installed and logged in (`claude auth login`)\n\n### Install\n\n```bash\ngit clone https://github.com/arktnld/claude-code-api.git\ncd claude-code-api\n\npython -m venv .venv\nsource .venv/bin/activate\npip install -e \".[dev]\"\n```\n\n### Configure\n\n```bash\ncp .env.example .env\n```\n\nEdit `.env`:\n```env\nAPPROVED_DIRECTORY=/home/user/projects\nAPI_KEYS=my-secret-key\n```\n\n### Run\n\n```bash\nmake dev\n```\n\nServer at `http://localhost:8000`. Docs at [`http://localhost:8000/docs`](http://localhost:8000/docs).\n\n## API Overview\n\n### Create a session\n\n```bash\ncurl -s -X POST http://localhost:8000/api/v1/sessions \\\n  -H \"X-API-Key: my-secret-key\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"name\": \"my-project\"}' | python -m json.tool\n```\n\n### Chat with Claude\n\n```bash\ncurl -s -X POST http://localhost:8000/api/v1/sessions/my-project/chat \\\n  -H \"X-API-Key: my-secret-key\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"message\": \"create a hello.py that prints Hello World\"}' | python -m json.tool\n```\n\n```json\n{\n  \"data\": {\n    \"session_id\": \"555a982f-...\",\n    \"content\": \"I've created hello.py with a Hello World print statement.\",\n    \"cost\": 0.003,\n    \"duration_ms\": 4521,\n    \"num_turns\": 2,\n    \"tools_used\": [\n      {\"name\": \"Write\", \"input\": {\"file_path\": \"hello.py\", \"content\": \"print('Hello World')\"}}\n    ]\n  },\n  \"meta\": {\"request_id\": \"abc123\", \"timestamp\": \"...\", \"version\": \"v1\"}\n}\n```\n\n### Stream responses (SSE)\n\n```bash\ncurl -N -X POST http://localhost:8000/api/v1/sessions/my-project/chat/stream \\\n  -H \"X-API-Key: my-secret-key\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"message\": \"read hello.py\"}'\n```\n\n### Use a template\n\n```bash\ncurl -s -X POST http://localhost:8000/api/v1/sessions \\\n  -H \"X-API-Key: my-secret-key\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"name\": \"review-auth\", \"template\": \"code-reviewer\"}' | python -m json.tool\n```\n\n\u003e See the full [API Reference](docs/api-reference.md) for all endpoints.\n\n## All Routes\n\n```\nHealth\n  GET    /api/v1/health                              Health check (no auth)\n\nSessions\n  POST   /api/v1/sessions                            Create session\n  GET    /api/v1/sessions                            List sessions (paginated)\n  GET    /api/v1/sessions/{name}                     Get session\n  DELETE /api/v1/sessions/{name}                     Delete session\n  POST   /api/v1/sessions/{name}/repo                Change working directory\n\nChat\n  POST   /api/v1/sessions/{name}/chat                Chat (sync)\n  POST   /api/v1/sessions/{name}/chat/stream         Chat (SSE stream)\n\nHistory\n  GET    /api/v1/sessions/{name}/history              Chat history\n\nJobs\n  POST   /api/v1/sessions/{name}/jobs                Create async job (202)\n  GET    /api/v1/sessions/{name}/jobs                List jobs\n  GET    /api/v1/sessions/{name}/jobs/{id}           Get job status\n  POST   /api/v1/sessions/{name}/jobs/{id}/cancel    Cancel job\n\nFiles\n  POST   /api/v1/sessions/{name}/files               Upload file\n  GET    /api/v1/sessions/{name}/files               List files\n  GET    /api/v1/sessions/{name}/files/{path}        Download file\n\nTemplates\n  GET    /api/v1/templates                            List templates\n  GET    /api/v1/templates/{name}                     Get template\n  POST   /api/v1/templates/reload                     Hot-reload from YAML\n\nUtilities\n  POST   /api/v1/tokens/count                        Estimate token count\n  GET    /api/v1/usage                               Usage statistics\n  GET    /api/v1/audit                               Audit trail\n```\n\n## Configuration\n\nAll settings via environment variables or `.env` file. See [Configuration docs](docs/configuration.md) for full reference.\n\n| Variable | Default | Description |\n|----------|---------|-------------|\n| `API_KEYS` | *(empty = no auth)* | Comma-separated API keys |\n| `APPROVED_DIRECTORY` | `.` | Root directory for sessions |\n| `CLAUDE_MODEL` | *(CLI default)* | Model override |\n| `CLAUDE_MAX_TURNS` | `25` | Max turns per request |\n| `CLAUDE_TIMEOUT_SECONDS` | `300` | Request timeout |\n| `SANDBOX_ENABLED` | `true` | OS-level bash sandboxing |\n| `RATE_LIMIT_REQUESTS` | `30` | Requests per window |\n| `CLAUDE_MAX_COST_PER_USER` | `50.0` | Max USD per user |\n\n\u003e Full list: [docs/configuration.md](docs/configuration.md)\n\n## Docker\n\n```bash\ndocker compose up --build -d\n```\n\nOr manually:\n```bash\ndocker build -t claude-code-api .\ndocker run -p 8000:8000 --env-file .env -v /your/projects:/projects claude-code-api\n```\n\n## Architecture\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"docs/architecture.svg\" alt=\"Architecture Diagram\" width=\"100%\"\u003e\n\u003c/p\u003e\n\n```\nsrc/\n├── main.py              # FastAPI app, lifespan, error handlers (RFC 9457)\n├── config.py            # Settings from env\n├── api/\n│   ├── routes.py        # Core endpoints + response envelopes\n│   ├── jobs.py          # Async job execution + webhooks\n│   ├── files.py         # File upload/download/list\n│   ├── extras.py        # Usage, templates, audit, moderation, tokens\n│   ├── deps.py          # Dependency injection\n│   └── middleware.py     # Request ID, body limit, security headers\n├── claude/\n│   ├── client.py        # claude-agent-sdk wrapper (execute, stream, retry)\n│   └── exceptions.py    # Error hierarchy\n├── sessions/\n│   └── manager.py       # Session lifecycle, budget, auto-resume\n├── security/\n│   ├── auth.py          # API key auth, rate limiter\n│   └── validators.py    # Path traversal, bash boundary checks\n└── storage/\n    └── database.py      # SQLite async (sessions, messages, jobs)\n```\n\n## Documentation\n\n\u003e Full documentation available on the [Wiki](https://github.com/arktnld/claude-code-api/wiki) and in the [docs/](docs/) folder.\n\n| Document | Description |\n|----------|-------------|\n| [Getting Started](docs/getting-started.md) | Installation, first session, first chat |\n| [Authentication](docs/authentication.md) | API keys, Claude auth modes |\n| [Sessions](docs/sessions.md) | CRUD, lifecycle, templates, working directories |\n| [Chat](docs/chat.md) | Sync, streaming, SSE format, idempotency |\n| [Jobs](docs/jobs.md) | Async execution, webhooks, cancellation |\n| [Files](docs/files.md) | Upload, download, list |\n| [Configuration](docs/configuration.md) | All environment variables |\n| [Security](docs/security.md) | Auth, rate limiting, sandboxing, moderation |\n| [Error Handling](docs/error-handling.md) | RFC 9457, status codes, examples |\n| [API Reference](docs/api-reference.md) | Complete route table with request/response |\n\n## Development\n\n```bash\nmake dev        # Hot-reload server\nmake prod       # Production (gunicorn)\nmake docker     # Docker compose\nmake test       # Run tests\nmake lint       # Check code\nmake format     # Auto-format\n```\n\n## Contributing\n\nContributions are welcome! Please open an issue first to discuss what you'd like to change.\n\n## Disclaimer\n\n\u003e [!CAUTION]\n\u003e This project is an **educational study** and proof of concept. It is **not affiliated with, endorsed by, or officially supported by Anthropic**.\n\u003e\n\u003e - This wraps Claude Code CLI via `claude-agent-sdk` — usage is subject to [Anthropic's Terms of Service](https://www.anthropic.com/terms)\n\u003e - **Do not** expose this API to the public internet without proper security measures\n\u003e - The authors are not responsible for any misuse, costs incurred, or damages\n\u003e - This is provided \"as-is\" for learning purposes — **use in production at your own risk**\n\n## License\n\n[MIT](LICENSE) — see [LICENSE](LICENSE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farktnld%2Fclaude-code-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farktnld%2Fclaude-code-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farktnld%2Fclaude-code-api/lists"}