Skip to main content

Best Practices

Guidelines for building reliable, secure, and efficient agents.

Agent Design

Keep Tools Focused

Each tool should do one thing well:

Write Clear Tool Descriptions

Claude uses descriptions to decide when to use tools:

Use CLAUDE.md Effectively

Structure your CLAUDE.md for clarity:

Error Handling

Handle Tool Failures Gracefully

Validate Inputs

Set Timeouts

Security

Never Trust User Input

Restrict File Access

Sanitize Command Execution

Use Secrets for Credentials

Performance

Minimize API Calls

Stream Large Outputs

For long responses, consider streaming:

Clean Up Resources

Testing

Test Locally First

Test Edge Cases

  • Empty prompts
  • Very long prompts
  • Prompts that might cause infinite loops
  • Prompts with special characters

Test Tool Failures

Monitoring

Log Important Events

Track Costs

Monitor your usage:

Deployment

Use Git for Versioning

Keep your agent in version control:

Document Your Agent

Include a README.md:

See Also

Debugging

Troubleshooting tips

Secrets

Managing credentials