This file provides guidance for AI coding agents working autonomously in this repository. It extends CLAUDE.md with agent-specific workflows and safety guidelines.
Prerequisites: Read and understand
CLAUDE.mdbefore using this file. That document contains essential build commands, architecture overview, and project structure.
-
Never modify consensus-critical code without explicit user confirmation
consensus/safety_rules/consensus/src/round_manager.rs- Any code affecting Byzantine fault tolerance
-
Never modify cryptographic code without explicit user confirmation
crates/aptos-crypto/- Signature verification logic anywhere
- Key generation or derivation
-
Prefer reversible changes: Make small, incremental commits that can be easily reverted
-
When in doubt, ask: If a change might affect security, consensus, or data integrity, pause and ask the user
- Start with semantic search for unfamiliar areas
- Use grep for exact symbol lookups (function names, types, constants)
- Read CLAUDE.md for architecture context before major changes
- Check existing tests to understand expected behavior before modifying
- Review git history for related changes:
git log -p --follow -- <file>
1. Reproduce: Understand the bug via tests or user description
2. Locate: Find relevant code using search tools
3. Analyze: Read surrounding code and tests
4. Fix: Make minimal change to fix the issue
5. Test: Run relevant tests
cargo test -p <package> <test_name>
6. Verify: Check no regressions
cargo test -p <package>
7. Lint: Ensure code quality
cargo xclippy -p <package>
cargo +nightly fmt --check
1. Understand: Read related code and architecture
2. Design: Plan minimal implementation
3. Implement: Write code following existing patterns
4. Test: Add unit tests alongside implementation
5. Integrate: Update any affected modules
6. Verify:
cargo build -p <package>
cargo test -p <package>
cargo xclippy -p <package>
1. Locate: Find module in aptos-move/framework/<package>/sources/
2. Understand: Read module and its tests
3. Modify: Make changes to Move code
4. Test Move: cargo test -p <framework-package>
5. Rebuild cached packages (REQUIRED):
cargo build -p aptos-cached-packages
6. Verify: Check for uncommitted generated files
git status aptos-move/framework/cached-packages/
1. Locate: Find endpoint in api/src/
2. Modify: Update implementation
3. Regenerate OpenAPI specs:
cargo run -p aptos-openapi-spec-generator -- -f yaml -o api/doc/spec.yaml
cargo run -p aptos-openapi-spec-generator -- -f json -o api/doc/spec.json
4. Test: cargo test -p aptos-api
- Highly sensitive: Changes affect all Move execution
- Platform agnostic part of Move execution
- Always test with:
cargo test -p move-vm-runtime - Verify gas metering isn't affected unintentionally
- Highly sensitive: Changes affect all Move execution
- Aptos specific part of Move execution: parallel, gas, prologue, epilogue
- Check parallel execution:
cargo test -p aptos-vm
- Parallel execution core: Changes affect transaction throughput
- Test both sequential and parallel modes
- Check for MVCC conflicts and read/write set handling
- Key tests:
cargo test -p aptos-block-executor
- Data persistence: Changes can affect all stored data
- Always verify backup/restore after changes
- Test pruning behavior
- Key tests:
cargo test -p aptos-db
- DO NOT modify without explicit approval
- Changes require extensive testing with Forge
- Must maintain 3f+1 Byzantine fault tolerance
# Check compilation
cargo check -p <package>
# Run package tests
cargo test -p <package>
# Check lints for package
cargo xclippy -p <package># Full lint check
./scripts/rust_lint.sh --check
# Or individual checks
cargo xclippy
cargo +nightly fmt --check
cargo sort --grouped --workspace --check# Core packages
cargo test -p aptos-vm -p aptos-types -p aptos-crypto
# Framework
cargo test -p aptos-framework -p aptos-stdlib
# Smoke tests (slower but comprehensive)
cargo test -p smoke-test# Find function definitions
grep -r "fn function_name" --type rust
# Find trait implementations
grep -r "impl.*TraitName" --type rust
# Find type usages
grep -r "TypeName" --type rust --glob "*.rs"
# Find Move module
grep -r "module.*::module_name" --glob "*.move"# Show what a package depends on
cargo tree -p <package>
# Show what depends on a package
cargo tree -p <package> --invert
# Find duplicate dependencies
cargo tree -d- Unit tests: Same file as code, in
#[cfg(test)] mod tests { ... } - Integration tests:
<crate>/tests/directory - E2E tests:
aptos-move/e2e-tests/ - Move tests:
aptos-move/framework/*/tests/ - Smoke tests:
testsuite/smoke-test/
# Clean and rebuild
cargo clean -p <package>
cargo build -p <package>
# Full clean (last resort)
cargo clean
cargo build# Force rebuild cached packages
cargo clean -p aptos-cached-packages
./scripts/cargo_build_aptos_cached_packages.shcd protos && ./scripts/build_protos.sh# Auto-fix formatting
cargo +nightly fmt
# Sort dependencies
cargo sort --grouped --workspace
# Check for unused deps
cargo machete --fix- Run
cargo checkafter any Rust code change - Run tests for modified packages
- Check existing tests before modifying behavior
- Follow existing code style in the file
- Use the type system for safety (prefer
Resultoverpanic!)
- Modify
consensus/safety_rules/ - Change signature verification logic
- Alter gas metering significantly
- Delete or rename public API endpoints
- Modify database schema
- Change network protocol messages
- Unsure about backwards compatibility
- Change affects multiple packages
- Modifying critical path (consensus, execution, storage)
- Adding new dependencies
- Performance implications unclear
- Avoid unnecessary allocations in hot paths
- Use
Arcfor shared data across threads - Prefer iterators over collecting to
Vec - Check Block-STM compatibility for VM changes
- Profile before optimizing:
cargo run -p aptos-vm-profiling
When modifying one component, verify these integration points:
| Component | Affects | Verify With |
|---|---|---|
| VM | Execution, Gas | cargo test -p aptos-vm -p aptos-block-executor |
| Framework | VM, API | cargo test -p aptos-framework && cargo build -p aptos-cached-packages |
| Storage | Everything | cargo test -p aptos-db -p aptos-executor |
| API | Clients | cargo test -p aptos-api + check OpenAPI spec |
| Types | Everything | cargo test -p aptos-types |
| Network | Consensus, Sync | cargo test -p aptos-network |
- Rust:
snake_case.rs - Move:
module_name.move - Tests:
*_test.rsor intests/directory - Configs:
*.yamlor*.toml
[area] Brief description
- Detailed change 1
- Detailed change 2
Example:
[vm] Fix gas metering for vector operations
- Corrected gas calculation for vector push
- Added unit tests for edge cases
Areas: vm, framework, consensus, storage, api, network, types, cli, docs, test