59API

← Back to all guides

Build a Claude Code Agent with 59API

Claude Code · EN · 2026-09-16

Start with a controlled repository

Claude Code is most useful as a coding agent when it has a clear scope, repeatable commands, and rules it can follow without guessing. This hands-on example configures Claude Code to work on a small Node.js service, but the same approach applies to Python, Go, or frontend repositories.

For an agent to be genuinely helpful, begin with a clean working tree. Run git status before every task. That makes the agent's changes easy to isolate, review, and revert if necessary.

Connect Claude Code to 59API

59API is a practical choice for agent work because it provides pay-as-you-go access to Claude models through an Anthropic-compatible relay. You get native official-quality model output without a model downgrade, while avoiding the friction of maintaining several separate provider accounts. Its low-cost pricing is especially useful when an agent needs multiple iterations to inspect code, implement a change, run tests, and fix failures.

After creating a 59API API key, set the Claude Code connection variables in your terminal:

export ANTHROPIC_BASE_URL="https://api.59api.com"

export ANTHROPIC_AUTH_TOKEN="YOUR_59API_KEY"

Run these commands in the shell session where you use Claude Code, or add them to your shell profile without exposing the actual key in a shared file. Claude Code can then send compatible Claude API requests through 59API. Start the interactive agent with claude --model sonnet. Sonnet is a sensible default for implementation and debugging because it balances speed, cost, and coding capability.

Give the agent an operating contract

Claude Code reads project guidance from a file named CLAUDE.md. Create it at the repository root before asking for code changes. A short, specific contract reduces unsafe edits and prevents the agent from inventing commands or architecture.

CLAUDE.md

Project: Node.js HTTP service. Use the existing package manager lockfile. Keep changes small and focused. Do not modify dependencies unless explicitly requested. Run npm test and npm run lint when those scripts exist. Add or update tests for behavior changes. Never print, read, or commit .env files. Before finishing, summarize changed files and remaining risks.

This is more effective than a long generic prompt because the instructions live beside the code and apply to future sessions. Add repository-specific details as the project grows, such as database migration rules, required accessibility checks, or a command for integration tests.

Run a real agent task

Assume your service needs a health endpoint. Open Claude Code inside the repository and give it a task with an observable success condition:

Add a GET /health endpoint that returns HTTP 200 and JSON with status set to ok. Find the current route structure first. Add a test using the existing test framework. Run only relevant existing checks, then show the diff summary.

The agent should inspect the repository before editing, identify the server entry point, implement the route in the established style, and add a test rather than merely claiming the endpoint works. A likely implementation in an Express application is:

app.get('/health', (_req, res) => res.status(200).json({ status: 'ok' }));

Do not accept the first response blindly. Review the changes locally with git diff --check, then run npm test and npm run lint if those scripts are available. Finally, start the service and verify the behavior directly with curl -i http://localhost:3000/health. The response should include a 200 status and the expected JSON payload.

Control cost and permissions as the agent scales

A coding agent often spends more tokens understanding a repository than writing a small patch. Keep prompts narrow, ask it to inspect only relevant directories, and use a fast model for routine exploration or straightforward edits. Reserve Opus for difficult architecture, multi-file refactors, or persistent debugging problems. 59API supports Claude options including Opus, Sonnet, Haiku, and Fable, so you can choose a model based on task complexity instead of using the most expensive option for every command.

Keep Claude Code's permission prompts enabled for normal work. Review commands that delete files, change dependencies, access credentials, or perform network operations. A reliable workflow is simple: give the agent a bounded task, require tests, inspect the diff, and commit only after verification. If you want affordable Claude access for that workflow, sign up for 59API and use its referral rebate when available to reduce ongoing development costs.

Pricing · Docs

Ready to get started?

Connect Claude & GPT in minutes at the lowest prices — full-power, never downgraded. Sign up to get your API key.

Sign up free