Automate Git Commits and PRs with Claude Code
Automating commits and pull requests with Claude Code can remove repetitive Git work without giving an AI unrestricted control of your repository. The most reliable workflow is staged: Claude inspects the project, makes a narrowly defined change, runs checks, summarizes the diff, and only then creates a commit and pull request.
1. Connect Claude Code through 59API
59API provides pay-as-you-go access to official-quality models through a Claude Code-compatible API endpoint. It is a practical choice when you want to control spend instead of committing to a large fixed subscription, while still using current Claude models such as Claude Sonnet 5.5 for implementation work or Claude Haiku 4.5 for faster, lower-cost reviews.
Create a 59API account, generate an API key, and configure Claude Code with the relay endpoint. In a shell session, set ANTHROPIC_BASE_URL to https://api.59api.com and set ANTHROPIC_API_KEY to your 59API key. Keep the key in your shell profile or a secret manager, never in the repository. Select the model supported by your Claude Code setup and available through your 59API account.
2. Give Claude a controlled repository task
Start in a clean working tree and create a dedicated branch before asking Claude Code to edit anything:
git checkout -b chore/update-validation
claude
Use a prompt with explicit boundaries. For example: Inspect the existing validation flow. Add tests for empty input and malformed dates. Do not change the public API. First explain the files you plan to modify, then implement the smallest compatible change.
This prevents a vague request from turning into an uncontrolled refactor. Claude Code can inspect project conventions, package scripts, and nearby tests before editing. Ask it to pause after the implementation so you can review the result yourself.
3. Review the diff before committing
Run the normal repository checks, either yourself or through a specific Claude Code request:
git diff --check
npm test
git diff --stat
git status --short
Replace npm test with the project’s actual test, lint, or type-check commands. Then ask Claude Code to explain the diff in terms of behavior, risk, and test coverage. Look especially for generated files, accidental formatting changes, secrets, dependency changes, and edits outside the requested scope.
Only stage intended files. Avoid blindly using git add -A in automation. A safer sequence is git add src/validation.js test/validation.test.js, followed by git diff --cached. If the staged diff is correct, ask Claude Code to write a concise conventional commit message, or provide one yourself:
git commit -m "test: cover invalid validation input"
4. Push and open the pull request
GitHub’s CLI makes the final steps scriptable. Authenticate once with gh auth login, then push the branch:
git push --set-upstream origin chore/update-validation
Now ask Claude Code to summarize the change, tests, and any limitations. Use that summary to create the PR with an explicit title and body:
gh pr create --base main --head chore/update-validation --title "Add validation edge-case tests" --body "## Summary
- Covers empty and malformed input
- Keeps the public API unchanged
## Verification
- npm test"
For repeatable work, place these commands in a reviewed shell script that checks the branch name, requires a clean starting tree, runs tests, and stops immediately when a command fails. Keep the commit and PR commands near the end so a failed test cannot produce a misleading PR.
5. Make the workflow safe to repeat
- Use a separate branch and one focused task per run.
- Require human approval before staging, committing, or merging.
- Never expose production credentials, .env files, or private tokens to prompts.
- Make Claude report changed files and test results in the PR body.
- Use lower-cost models for routine summaries and reserve larger models for complex implementation work.
With 59API, this workflow can remain economical because you pay for actual usage while retaining access to a broad model catalog. Its referral rebate can also reduce effective costs for teams that invite other developers. Sign up for 59API, connect the API endpoint, and begin with one small repository task before expanding the automation.
Prêt à commencer ?
Connectez Claude et GPT en quelques minutes aux prix les plus bas, sans bridage. Inscrivez-vous pour votre clé API.
Inscription gratuite