Reviewing Claude Code’s Work: Security and Performance

A generated test in an authentication service claimed to check for SQL injection. It didn't attempt an injection or verify that the database was unaffected. I asked Claude Code to rewrite it so it checked the database's state.

That has been a recurring part of my work with Claude Code: deciding what evidence would make a proposed change acceptable, then checking whether the implementation and tests provide it. I call the coding practice synthesis coding, within the broader synthesis engineering discipline.

Claude Code: TODO: Everything. Let's start. Claude Code's opening screen.

I like working in the terminal alongside the code, tests, and version history. Claude Code can help examine related files and apply a change across them. That makes it useful for tracing a route through a service and repository to its tests. It also leaves plenty to inspect: a missed call site, a misunderstood boundary, or a test that approves its own assumptions.

Put the project's constraints where the tool can use them

Updated December 19, 2025: Added guidance on persistent project context across sessions.

In the authentication project, the architectural choices included PostgreSQL, SQLAlchemy, a repository for data access, and a service layer for business logic. Giving those decisions to Claude helped make its proposals relevant to the existing system.

A durable instruction file also gives the next session a place to find that context. It should explain the rules that affect the work, point to their rationale, and identify how to check them. A project template might look like this:

# Project instructions

## Architecture
- PostgreSQL with SQLAlchemy ORM
- Repository pattern for data access
- Service layer for business logic
- JWT authentication with a one-hour token lifetime

## Coding standards
- Use type hints on functions
- Run the relevant tests before merge
- Project coverage floor: 80%; review behavior beyond the percentage
- Error responses follow RFC 9457 problem details

## Domain context
- Users can belong to multiple organizations
- Billing uses the Stripe integration
- Persist timestamps as UTC instants
- Check authorization before returning organization-specific data

An 80% coverage floor is a project policy, not evidence that the remaining behavior is safe. A UTC rule needs examples of the timestamps it governs. And a token lifetime needs enforcement at validation, not just a sentence in a file. RFC 9457 supersedes RFC 7807 for the problem-details format.

Current instruction loading, documentation checked October 1, 2026: Claude Code supports CLAUDE.md and, under its documented discovery and configuration conditions, AGENTS.md. Codex also uses AGENTS.md, with its own discovery, precedence, and size rules. The filenames do not divide instructions into human-written and AI-written categories. A singular AGENT.md is not a portable convention to assume will load. Check the tool's documentation and inspect what it loaded in the actual session. Claude Code memory documentation, Codex instruction documentation.

Stored context can survive a conversation. It can also be stale, omitted by the loading rules, or misunderstood. Keep the instruction file short enough to maintain, link the architectural decisions behind it, and enforce testable requirements in tests or tooling.

In late 2025, teams practicing synthesis coding reported that well-maintained context files reduced their context-setting time from 15–20 minutes per session to nearly zero.

Authentication: decide what happens when a control fails

I used Claude Code to add rate-limited user authentication to an existing API service. The initial specification was concrete: PostgreSQL and SQLAlchemy, JWTs with a one-hour expiry, Redis for login throttling, bcrypt with cost 12, Pydantic response models, and structured logs with correlation IDs.

The original limits were five login attempts per IP per minute and an account lockout after ten failed attempts for an hour. Those were choices for that system. They need review against abuse patterns and the risk of locking out legitimate users. An IP limit alone does not stop attempts spread across many addresses; OWASP's guidance also considers account-based controls and denial-of-service consequences. Authentication Cheat Sheet.

The password choice also belongs to its time and application. For a new system, consult current guidance: OWASP prefers Argon2id and treats bcrypt as a choice for legacy systems where the preferred options are unavailable. Cost settings need measurement on the deployment hardware. Password Storage Cheat Sheet.

Review the contract before the implementation

Claude asked about token refresh, password requirements, account lockout, and session management. Those questions exposed decisions the first prompt had left open. Answering them gave us something more useful to implement and review than “add authentication.” Those two or three minutes of architectural clarity save hours of refactoring later.

The generated files included a SQLAlchemy user model, repository, and migration. In this codebase, returning None for a missing user made downstream error handling awkward. I asked for an explicit UserNotFound exception. That was an internal interface choice. It would not justify telling an unauthenticated caller whether an account exists; login responses and their timing need separate scrutiny.

During the security review, I checked password handling, throttling, and token generation. I found that token generation omitted the expiry claim. The requirement said one hour, but the implementation did not encode that limit. The acceptance check needed to cover both issuing the expiry and rejecting an expired token.

For a JWT-based service, use a maintained library and explicitly configure the permitted algorithms and applicable issuer, audience, and claim checks. A token that can be decoded is not necessarily valid. The IETF's JWT best-current-practice document describes these validation boundaries.

A Redis outage is an authentication-policy decision

The first version of this article recommended failing open when Redis was unavailable. That would let new login attempts bypass the abuse control precisely when it could not enforce its limit. A circuit breaker can stop repeated calls to a failing dependency; it does not make bypassing a security control acceptable.

A service needs a deliberate policy. It might use an independently enforced fallback with a tested limit. Without that fallback, affected new attempts should receive a controlled temporary failure. Existing authenticated sessions are a separate policy question; a failure in new-login throttling does not, by itself, determine their treatment. OWASP includes fail-open behavior among the risks in mishandling exceptional conditions.

Implement the agreed policy for new login attempts.

- If the primary abuse control denies the attempt, do not continue.
- If it is unavailable, use only the separately enforced fallback.
- If neither control can decide, return a controlled temporary failure.
- An allowed attempt still has to pass credential verification.
- Do not log passwords, tokens, or other authentication secrets.

Test primary denial, backend outage, fallback denial, and both controls
being unavailable. Keep the existing-session policy separate.

The downloadable review examples include a local model of that policy. It accepts an ALLOW, DENY, or UNAVAILABLE decision from each control. Its result permits credential checking, throttles the attempt, or reports the unavailable control. The example does not implement Redis, a fallback service, or authentication.

Inspect what the tests establish

The original authentication work produced more than 100 tests. I reviewed their assertions, which is how I found the ineffective injection test.

For this service, the review list included successful registration and login; token generation and validation; expired and invalidly signed tokens; login throttling and account lockout; Redis and database failures; concurrent attempts; and token boundary times. Where a test claimed to exercise SQL injection, it needed to reach the relevant data-access path and check the intended result and database state.

My time accounting was 15 minutes for architectural planning, 45 for implementation iterations, 30 for security review and refinement, and 25 for generating and reviewing tests: 115 minutes. I had a complete authentication implementation, and I maintained the same, arguably higher, quality standards through systematic review. Doing the same work without AI assistance would have taken me an estimated six to eight hours.

A slow dashboard: verify each proposed bottleneck

A dashboard endpoint was taking two to three seconds to respond, and users were complaining. I asked Claude Code to examine database queries, serialization, external calls, missing indexes, and cache opportunities.

It returned several leads: an N+1 query pattern, an unindexed filter on posts.user_id, sequential avatar fetching, serialization overhead, and repeated construction of dashboard data.

The N+1 issue appeared in our application-performance monitoring: loading the dashboard triggered dozens of queries. The avatar lead looked different when I checked the running system; those requests were cached by a CDN. That changed its priority. The missing index was worth investigating against the actual query and table.

I asked Claude to change the SQLAlchemy query to eager loading and show the SQL. Eager loading is a standard way to address relationship-related N+1 queries, but the chosen loading strategy and query count still need inspection in the application. SQLAlchemy's relationship-loading documentation.

The next request was a migration for the index on posts.user_id. I reviewed it against the data and query patterns. A generated explanation of what the query planner should do is a hypothesis to compare with an actual plan.

Cache expiry and invalidation are different problems

The cache specification used dashboard:{user_id}, a five-minute TTL, and invalidation on post creation or profile changes. It also required hit and miss metrics.

A key must represent everything that determines the cached answer. If a dashboard varies by organization, permission, or another input, a user-only key needs further design. Namespacing avoids some collisions; it does not establish correct isolation.

The original request for “cache invalidation locking” also mixed two problems. Invalidation removes or supersedes stale content when underlying data changes. A cache stampede happens when many requests encounter a miss and all start rebuilding the same entry. Locking only the invalidation path does not coordinate those fills after expiry.

Review concurrent cache misses for one dashboard key.

Show what happens when several requests see an expired entry.
Coordinate the fill where required, and recheck the cache after acquiring
that coordination mechanism. Specify the wait limit and failure behavior.

Separately test an update arriving while an older value is being rebuilt.
Check that the result satisfies our freshness and authorization rules.

A distributed lock brings its own assumptions. Ownership checks on release and a lease that expires while work is still running matter; a ten-second timeout alone does not settle correctness. Redis documents those constraints in its locking guidance. The local download accompanying this article does not test distributed caching.

Measure the result under a stated load

The generated Locust test simulated 100 concurrent users for 60 seconds, requesting the dashboard and reporting latency percentiles, query count, and cache hit rate. I ran it against staging.

Measure in that runBeforeAfter
Median latency2,100 ms180 ms
95th-percentile latency3,400 ms340 ms
Queries per request451
Cache hit rateNo cache87%

The latency reductions were about 91% at the median and 90% at the 95th percentile. Systematic analysis, targeted optimization and rigorous validation produced the improvement. AI accelerated each phase while I maintained architectural control and quality standards.

The CDN finding mattered because it kept a plausible code-level explanation from becoming unnecessary work.

An async function can still block the event loop

In an agentic workflow system, I expected three independent model calls taking 25–30 seconds each to complete together in about 30 seconds. They took more than 90.

The system used Python's async syntax, and PostgreSQL had a pool of 20 connections plus ten overflow connections. Neither fact explained why the model calls overlapped so poorly.

After about 20 minutes of investigation, I found a synchronous anthropic.Anthropic() client inside the async functions. Calling its blocking method occupied the event-loop thread. Declaring the surrounding function async did not turn that operation into asynchronous I/O.

The correction used AsyncAnthropic and awaited the call. This SDK sketch requires an installed SDK, a configured client, an available model, and an actual provider call:

from anthropic import AsyncAnthropic

async def generate_variant(
    client: AsyncAnthropic, prompt: str, model: str
) -> str:
    response = await client.messages.create(
        model=model,
        max_tokens=4096,
        messages=[{"role": "user", "content": prompt}],
    )
    return "".join(
        block.text for block in response.content if block.type == "text"
    )

The current Anthropic Python SDK documentation describes this async client and the awaited methods. The caller must also schedule independent work concurrently; changing a client does not make a sequence of awaited calls overlap automatically.

The refactor request named four files: services/ai_client.py for initialization, agents/research.py with three call sites, agents/synthesis.py with two, and agents/validation.py with one. That is six call sites across three agent files, plus the client-initialization file. I reviewed the changes for awaited calls and the functions that invoked them.

After the refactor, the three calls completed in 32 seconds in my test, roughly three times faster than the earlier run.

Bound concurrent work and provider usage separately

I then asked for a limit of 30 simultaneous model calls. A semaphore can enforce a simultaneous-work bound: an operation acquires a permit, does its work, and releases the permit. It does not count requests or tokens over a provider's time window. Python documents the semaphore's counter and waiting behavior in its asyncio synchronization reference.

The current Claude API has separate request and token limits, and reports limit errors with a 429 response and a retry interval. Thirty concurrent calls could exceed an allowance; one at a time could also exceed it if calls complete quickly. Matching a limit to a database pool does not establish the provider's allowance. Claude API rate limits.

Set separate policies for:

  • How many operations may be active, and how much work may wait?
  • How long may a request wait for a slot, and what happens when it cannot get one?
  • What request and token budgets apply to the actual account and model?
  • How are retries, deadlines, cancellation, and multiple workers coordinated?

Check SDK retries before adding another retry loop. The current Python SDK already retries selected failures by default; layering retries can multiply attempts.

Claude generated this wrapper in the original workflow:

import asyncio
from contextlib import asynccontextmanager

class RateLimitedAIClient:
    def __init__(self, max_concurrent: int = 30):
        self.semaphore = asyncio.Semaphore(max_concurrent)
        self.client = AsyncAnthropic(api_key=settings.anthropic_api_key)

    @asynccontextmanager
    async def acquire(self):
        async with self.semaphore:
            yield

    async def create_message(self, **kwargs):
        async with self.acquire():
            return await self.client.messages.create(**kwargs)

The semaphore wrapper in the original article implemented neither the requested wait timeout nor queue metrics. It also did not establish a fairness guarantee or prove starvation. If ordering is a requirement, specify and test it explicitly.

The local example has a ConcurrencyGate with a bound on admitted work, a wait timeout, and active/waiting counters. Tests cover cancellation and exceptions so an abandoned operation does not retain a slot. Its scope is one asyncio event loop.

Its counterexample is deliberately simple: eight mock requests have a synthetic start time of zero, while no more than two run simultaneously. That satisfies the concurrency bound and exceeds an illustrative quota of five starts in a minute. No provider requests are sent, and the synthetic clock is not a performance measurement.

A security finding needs a path to a violated rule

Before deploying an API service, I asked Claude Code for a systematic security review with file references, an explanation of the suspected problem, and a proposed repair.

The checklist in the original prompt followed the OWASP Top Ten 2017 categories, including XML external entities and insecure deserialization. Labeling its edition matters. OWASP's 2025 list is different, and either list is an awareness framework rather than a complete review of an application's threats.

Claude returned seven leads. I initially classified five as vulnerabilities and two as false positives or non-production concerns. The missing-admin-claim conclusion needed the correction explained below.

Reported leadWhat the review needed to establish
String formatting in a search queryWhether untrusted input reached SQL construction; repair with parameterized queries and test the affected data path.
Password hashes in an admin responseWhether the response was reachable and what it exposed. Calling it a development endpoint does not make disclosure harmless.
An admin route checked user.is_admin without an admin claim in the JWTWhether identity was validated and the server-side permission was trustworthy and current. The missing claim alone was not a defect.
DEBUG=True in settingsWhich configuration the production process used. In my review, the deployment override set it to false.
pickle.loads() on a webhook payloadWhether incoming data could reach unsafe deserialization. An internal endpoint still needed a safe format and verification.
Pillow 9.0.0 and CVE-2022-22817The installed version, affected functionality, and upgrade. The advisory is real; version alone does not prove an application's exploit path.
Missing logs for admin actions and authentication failuresWhich events the security policy required, and whether the relevant paths recorded them without secrets.

I treated the SQL construction and deserialization findings as real problems in that review. I also checked the development endpoint and deployment settings instead of accepting their classifications from filenames.

For the webhook, the repair request replaced pickle with JSON, added HMAC verification, rejected invalid signatures, and logged rejections. Parsing JSON is only one part of the contract: the receiver also needs agreed validation and replay handling for the actual webhook protocol. Standard Webhooks provides one concrete specification for signatures and replay handling.

An admin claim is one possible design, not the source of authority by itself

My original account treated the absence of an admin claim as a confirmed access-control defect. That conclusion did not follow from the described code.

A valid token can establish identity while the application obtains permission from a trusted current account record. A signed role claim is another design, with its own freshness and revocation rules. Requiring a duplicate claim does not automatically improve either design. OWASP recommends checking permissions on every request and denying access when the applicable policy does not grant it. Authorization Cheat Sheet.

For a policy based on current server-side roles, the tests should include a current administrator, an ordinary user, a disabled account, a mismatch between identity and account, and a formerly privileged user whose old token still carries an admin claim. Authentication itself also needs tests for missing, invalid, and expired credentials.

The local example takes an already validated identity and a current account record as inputs. Its policy requires a matching enabled account with current administrative permission. Tests demonstrate both directions: an old admin claim cannot restore revoked permission, and a current administrator does not need a redundant token role claim under this policy. The data classes are modeling inputs, not validating tokens; a real adapter must not construct trusted records from arbitrary request JSON.

Keep dependency and test evidence attached to the finding

Pillow's 9.0.1 release notes identify the fix for CVE-2022-22817 in ImageMath.eval. That supports correcting the affected dependency. The review still needs to distinguish a vulnerable installed component from a demonstrated reachable exploit, and verify the selected upgrade against the application's use.

I systematically remediated the real issues and covered the repairs with tests. The security work produced more than 40 tests and took about three hours. I reviewed whether the tests exercised the intended properties, including rejecting attacks and allowing legitimate requests. My estimate is that doing comparable manual work would have taken days. I directed the scope, validated the findings and prioritized the repairs; Claude helped make the analysis and test coverage systematic.

Run the examples, then review your own change

The review-cases download contains Python 3.11+ standard-library examples and tests. Extract it and run these commands from its review-cases directory:

python3 -m unittest -v
python3 review_cases.py demo
python3 review_cases.py verify
python3 review_cases.py verify --unsafe-counterexamples

The first three commands should exit successfully. The last deliberately selects unsafe teaching policies and should exit 1 with three failed checks. The source and the extracted download were each checked locally: 22 tests passed, the normal policy checks passed, and the three counterexamples failed as intended.

These examples test mechanisms. They do not reproduce the historical applications, authenticate a user, contact an AI provider, or establish that a service is secure.

Where I put the work

After hundreds of hours using this approach, I have a practical sense of where it helps most and where I need to spend more time.

Established patterns are productive starting points. CRUD APIs, routine database operations and cross-file modernization give the assistant recognizable structures to work with. Generating edge cases, security checks and error-path tests can make a review more systematic, provided I inspect what those tests actually assert. API documentation, architecture notes and runbooks are useful outputs too. Regeneration makes updates easier; somebody still has to notice the change and verify the new account.

Business rules, performance and legacy integrations need more iteration. A rule that makes sense in one organization may be wrong in another. An undocumented convention can carry years of operational knowledge. The dashboard case shows why a plausible optimization needs measurement against the running system. With a novel algorithm, I have less established behavior to use as a reference, so I spend more effort defining what a correct result would mean.

Distributed behavior and strategy demand my closest judgment. Race conditions and timing failures are difficult to reconstruct from a static view. Decisions about a monolith, microservices or an event-driven design depend on the team's constraints and the tradeoffs it can sustain. Product choices about what to build, for whom and in what order remain decisions I must own. I use AI to explore and challenge those decisions as well as to implement them; the authority to accept a tradeoff stays with the people responsible for its consequences.

My conclusion from these cases is that the approach amplifies engineering skill. Architectural thinking, quality standards and understanding become more valuable when implementation is faster. If I cannot explain generated code, I need to learn it or reject it. A systematic practice gives me a way to do that repeatedly, with different checks for different kinds of work.

For a real change, keep the requirement, diff, relevant test output, and observed behavior together. Ask what would still be wrong even if every supplied test passed. In the authentication case, that question led back to the injection test. In the dashboard case, the running system changed which proposed optimization was worth doing.

I am building and teaching synthesis engineering as a professional practice. I want that practice to grow into better architectural analysis with AI, closer integration with development tools, shared organizational methods and education that teaches engineers how to judge the work. Faster delivery is useful when we also build systems we can understand, maintain and improve.

December 2025 organizational update: Based on feedback from Guthrie Collin, I moved and expanded the organizational material into Scaling Synthesis Coding in Your Organization, covering cost, rollout, training, security, and adoption measures.

The synthesis terminology and my synthesis logo are available under CC0 1.0. If Anthropic or developer communities find the terms useful for documentation, training or a shared professional vocabulary, use them freely. The terminology exists to serve the practice.

Originally published at rajiv.com.