Skip to content
ContactDA
Published
Updated

How to use Claude Code and Codex in an existing codebase

Claude Code and Codex are most useful when they work inside a real repository with clear boundaries. Their advantage over a pasted code snippet is context: they can inspect related files, follow project instructions, review the current Git state, and run relevant checks when permissions allow it.

That context does not mean they understand the system automatically. A booking site, WordPress installation, Laravel application, or Astro frontend may contain years of decisions: old plugins, hosting constraints, payment flows, SEO workarounds, custom fields, API integrations, and content rules that are not obvious from one file.

Claude Code and Codex workflow for inspecting an existing codebase before making scoped changes

Map the repository before changing it

The first instruction should establish where the behavior lives and how the project is checked. Asking for a patch before this inspection encourages the agent to infer a pattern from too little context.

Useful starting questions include:

  • Which files control this behavior?
  • Which application, package, plugin, or service owns it?
  • What assumptions and business rules does the current code make?
  • Which tests, build commands, or manual checks cover it?
  • Are there local changes that must not be overwritten?
  • What could break outside the file that looks most obvious?

The result should be a short map of the relevant code, not a broad description of the whole repository. Inspection is useful only when it narrows the next decision.

Use agents for repository-shaped tasks

Claude Code and Codex are a better fit than browser chat when the answer depends on several files, project conventions, command output, or the current diff.

Useful repository-shaped tasks include:

  • Find where a route or content entry is generated
  • Trace a webhook from controller to database update
  • Explain why a build or focused test fails
  • Add validation to one existing form
  • Refactor one repeated helper without changing its output
  • Update one component while preserving its markup and styling intent
  • Review whether a proposed change follows the existing architecture

The task still needs a boundary. Broad instructions such as “modernize this site” or “clean up the whole theme” invite large diffs that are difficult to understand and risky to deploy.

Give each tool operational project instructions

Claude Code commonly reads project guidance from CLAUDE.md, while Codex uses AGENTS.md. The useful content is operational: repository structure, package manager, validation commands, architecture boundaries, deployment risks, and rules such as “do not redesign the interface unless asked” or “do not change public URLs without redirects”.

When both tools are used, shared rules should have one maintained source instead of drifting between two long files. The detailed setup belongs in AGENTS.md and CLAUDE.md for project instructions.

Instructions improve the default behavior, but they do not replace task-specific context. An agent still needs to know the intended result, what is out of scope, and how the change will be verified.

Keep Git state and permissions visible

Before an agent edits files, check whether the working tree already contains changes. Existing work belongs to someone and should not be overwritten merely because it is unrelated to the current request.

A controlled sequence is:

  1. Check the current Git state.
  2. Ask the agent to inspect relevant files without editing.
  3. Agree on the smallest useful change.
  4. Allow only the commands and file access the task needs.
  5. Review the resulting diff.
  6. Run the narrowest checks that can prove the result.

Permissions matter because repository agents can do more than suggest code. A command may update dependencies, rewrite generated files, change a database, call an external service, or remove local data. The agent should explain the effect before any action that is difficult to reverse.

Make one reviewable change

The implementation should be small enough that a developer can connect each changed line to the requested outcome. If inspection reveals a wider architectural problem, separate the immediate correction from the larger refactor instead of mixing both into one patch.

For a focused change, I check:

  • Did it change only the requested behavior?
  • Did it follow the existing architecture?
  • Did it preserve intentional edge cases?
  • Did it add dependencies or configuration changes?
  • Did it affect SEO, accessibility, forms, redirects, or tracking?
  • Can the change be verified with a command or a manual test?

When the task begins with a failure, use a diagnostic workflow that separates evidence, hypotheses, the smallest patch, and confirmation of the original problem. That process is covered in debugging with Claude Code and Codex.

Finish with evidence, not an agent summary

The final answer from Claude Code or Codex is a useful record, but it is not proof that the change works. Evidence may be a focused test, type check, build, reproduced browser flow, log comparison, webhook response, or generated-page inspection.

After verification, inspect the actual diff for regressions and hidden scope changes. The separate guide to AI code review with Claude and Codex explains how to structure that pass around concrete risks rather than asking whether the code merely “looks good”.

The practical standard is the same for both tools: understand the repository, constrain the task, keep the change reviewable, and verify the result in the system that will run it.

More articles