anthropic:claude-agent-sdk: copy working_dir into a new directory for each call and each repeat
Is your feature request related to a problem? Please describe.
The anthropic:claude-agent-sdk provider runs each call in working_dir as it is. When an agent writes files there, the next call of the same test sees those files. This breaks --repeat for any eval where the session edits a fixture, because repeat 2 starts from the state that repeat 1 left behind.
A minimal case: the fixture is a small repository, and the test asks the agent to add one file. With --repeat 3, run 1 writes the file and passes. Run 2 finds that file, writes another one, and a check that counts files fails. All three results report the same working_dir path.
To get a clean directory for each test today, the config must copy the fixture itself (mkdtemp plus cpSync) when it loads. That gives one copy for each test, not one for each call. The provider and the assertions then read that path at load time, so --repeat and any retry reuse the same directory.
Describe the solution you'd like
A provider option that treats working_dir as a template and copies it into a new temporary directory for each call, including each repeat. For example:
providers:
- id: anthropic:claude-agent-sdk
config:
working_dir: ./fixtures/sample-repo
copy_working_dir: trueAssertions then need the path of the copy that the call used. It can be exposed in the response metadata, for example metadata.workingDir, so that a javascript assertion or agent-rubric can read the files that this call wrote.
Describe alternatives you've considered
- Run promptfoo once for each repeat, as separate processes, so each process makes new copies when it loads the config. This works, but it gives up
--repeatand merges the results outside promptfoo. - A
beforeEachextension hook. It can change the test case, but the provider and itsworking_dirare already set by then, so it cannot give each call a new directory. - Resetting the directory between calls. This fails when calls run at the same time, which
--repeatdoes with the default concurrency.
Additional context
Related: #9915, which asks for per-test working_dir through {{var}} templates. That solves the choice of the directory, but not the isolation between calls of the same test.
Seen on promptfoo 0.123.0.
Source: promptfoo/promptfoo