Skip to main content
Local Cache writes action results to your filesystem so they persist across script runs. It works in both 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
Local caching can be used independently or together with Server Caching.

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

Organize caches by workflow or feature for easier management:
If the website structure changes significantly, clear your cache directory to force fresh inference:
Or programmatically:
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.