LOCAL and BROWSERBASE environments. When you specify a cacheDir, Stagehand saves every action and agent step to a local file on first run, then replays those cached actions on subsequent runs with no LLM calls, no token cost, and no network round-trip to Browserbase.
This is especially useful for:
- CI/CD pipelines - commit your cache directory to version control for consistent, deterministic runs across environments
- Local development - iterate on automations without burning tokens on repeated runs
- Cross-machine sharing - cache files are portable and can be shared across machines
Caching with act()
Cache actions from act() by specifying a cache directory in your Stagehand constructor.
Caching with agent()
Cache agent actions (including Computer Use Agent actions) the same way. Just specify a cacheDir. The cache key is automatically generated based on the instruction, start URL, agent execution options, and agent configuration. Subsequent runs with the same parameters will reuse cached actions.
Cache Directory Organization
You can organize your caches by using different directory names for different workflows:Best Practices
Use descriptive cache directories
Use descriptive cache directories
Organize caches by workflow or feature for easier management:
Clear cache when DOM changes
Clear cache when DOM changes
If the website structure changes significantly, clear your cache directory to force fresh inference:Or programmatically:
Commit cache for CI/CD
Commit cache for CI/CD
Consider committing your cache directory to version control for consistent behavior across environments:This ensures your CI/CD pipelines use the same cached actions without needing to run inference on first execution.

