What the agent does
The agent sorts the calls by argument before it changes one, because new Buffer(x) did different things for different x and the replacement depends on which. In a small library like ashtuchkin/u2f, which verifies U2F security-key registrations and signatures, index.js has seven calls and test/main-test.js has thirteen. Two of the seven decode fixed hex constants, on lines 21 and 142. The other five, on lines 119, 130, 176, 187 and 199, decode base64 strings that arrive from the caller: registerData.clientData, registerData.registrationData, signResult.clientData, signResult.signatureData and a stored public key. Every one passes a string and an encoding, so every one becomes Buffer.from(value, encoding). None allocates by size, which is the case that would need Buffer.alloc.
It then shows where the warning does and does not appear, which explains why libraries keep this code for years. Running npm test, which is mocha test, on Node 22 passes all five tests and prints the warning once: [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. With --trace-deprecation the first frame is test/main-test.js line 7. But when the package is installed into another project and called from there, nothing is printed, because Node raises this warning only for code outside node_modules. The library's users never see it; the maintainer sees it only from the test file.
With the calls replaced in both files, the agent runs the suite under --throw-deprecation, which turns any remaining deprecated call into a thrown error with a stack, and expects five passes and no output. It also probes the inputs the tests never send. The five caller-supplied values come from a browser by way of a JSON body, so their type is whatever the client chose to send. Passing a number as clientData makes checkRegistration throw TypeError [ERR_INVALID_ARG_TYPE] from line 119, where every other bad input returns an object with an errorMessage. Buffer.from throws for a number as well, so the port neither causes nor cures this.
The agent reports that as a separate finding and, if the prompt allows, adds a type check ahead of each decode so a non-string returns the same kind of error object as malformed JSON does, with a test for it. It leaves the package's public functions and their return shapes as they are, and it notes that package.json has no engines field to tell users which Node the new calls need.
Start it with one API call
POST https://api.phoenix.so/o/{org}/sessions with this body:
{
"agent": "claude",
"input": "This project prints: [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead. Remove every use of the Buffer constructor. Find each new Buffer(...) and bare Buffer(...) call in source and tests, excluding node_modules, and list it with file, line and what its first argument is: a string literal, a string from a caller, a number, an array, another buffer, or a value whose type is not fixed at the call site. Replace string, array and buffer arguments with Buffer.from, keeping the encoding. Replace a numeric size with Buffer.alloc; use Buffer.allocUnsafe only where the code provably overwrites every byte before reading, and say why. Where the type is not fixed, read the callers, state which types can arrive, and add an explicit check instead of guessing. Run the tests before the change and quote the warning with --trace-deprecation; run them after with --throw-deprecation and report the summary. Then call each public function that decodes caller input with a number, an object and an empty string, and report what it returns or throws before and after; if a wrong type throws where other bad input returns an error value, add a guard that returns the same kind of error and a test for it. Do not change public function names or return shapes. Add an engines field if the package has none. Open a pull request with the call table, both test runs and the probe results.",
"resources": [
{
"url": "https://github.com/your-org/your-app"
}
]
}- Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
- Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
- Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.
What comes back
A pull request touching index.js, test/main-test.js and package.json. Twenty constructor calls become Buffer.from, seven in the library and thirteen in the tests. The description has the table of calls with the argument kind beside each, which is the evidence that no Buffer.alloc was needed here, and the two test runs: five passing with one warning before, five passing under --throw-deprecation after.
The probe results follow as a small grid: each public function that decodes input, each wrong-typed value, and what came back. Where the agent added a guard, the grid shows the thrown TypeError in the before column and an errorMessage object in the after column, and the new test is named. This part is worth a reviewer's attention in an authentication library, since a route that hands a request body straight to checkRegistration could be made to throw by a client.
A reviewer also decides the engines value. Buffer.from and Buffer.alloc are absent from very old Node releases, so the change sets a floor that the package never declared. The description proposes a value and notes that the development dependency is still Mocha 2, which runs on Node 22 in this check but is far behind.
Run it on every test run that prints DEP0005
A warning does not fail a build, so nothing alerts on it. Make it fail once: add a scheduled CI job that runs the test command with NODE_OPTIONS=--throw-deprecation. When that job fails and its log contains DEP0005, a following step posts the stack trace to the URL of a webhook trigger on an automation that holds the prompt above, with Authorization: Bearer and the trigger's secret kept as a repository secret. The trace is placed after the saved prompt, and it names the file and line of the first constructor call.
Because Node stays silent about packages under node_modules, your applications will not report this for libraries you publish. For those, list the repositories that contain new Buffer( and start one run for each through the API, with a request_id that is a UUID v5 of the repository name so a repeated sweep starts no duplicates.
The use case this job follows, with its automation and trigger: Fix a bug from an alert.
Why run it on Rush?
The edit is a search and replace until one call takes a number or a value of unknown type, and then it is a security decision: new Buffer(n) allocates n bytes, and the constructor was deprecated because code written for strings could be handed a number. Telling the cases apart means reading each call and its callers. The agent does that for all of them, runs the suite with deprecations as errors in its own sandbox, and the transcript keeps the trace and both test runs.
It also tests inputs nobody wrote a test for. A constructor that accepts several types hides what a function does when it gets the wrong one. Probing each decode with a number, an object and an empty string takes a few minutes of machine time, and in a library that parses credentials from a browser it is the part of the pull request most likely to matter.
Frequently asked questions
When should I use Buffer.from, Buffer.alloc or Buffer.allocUnsafe?
Buffer.from when you already have the data, as a string with an encoding, an array or another buffer. Buffer.alloc(size) when you want a zero-filled buffer of a given length. Buffer.allocUnsafe(size) skips the zero fill and may expose old memory, so it is only for code that overwrites every byte before reading any.
Why do I see the warning in one project and not another that uses the same package?
Node prints DEP0005 only when the constructor is called from code outside node_modules. The same call inside an installed dependency is silent unless you start Node with --pending-deprecation. That is why the agent searches the source for the constructor and does not rely on the warning as an inventory.
Is this only cosmetic?
The warning is, the reason for it is not. The constructor chooses its behaviour from the argument's type, so a value that was meant to be a string and arrives as a number produces a buffer of that many bytes. The replacement functions each do one thing, which removes that ambiguity.
Will the agent change code inside node_modules?
No. It fixes calls in your own source and tests. For a dependency that still uses the constructor it reports the package, the version installed and whether a newer release has moved to Buffer.from, and proposes that upgrade separately.