Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions pkg/cmd/betafile.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"context"
"fmt"
"os"
"strings"

"github.com/anthropics/anthropic-cli/internal/apiquery"
"github.com/anthropics/anthropic-cli/internal/requestflag"
Expand All @@ -15,6 +16,21 @@ import (
"github.com/urfave/cli/v3"
)

const managedAgentsBeta = "managed-agents-2026-04-01"

// addManagedAgentsBetaForFiles appends the managed-agents beta header when the
// request targets a session-scoped file (scope-id prefixed with "sesn_").
// Session-scoped file operations require this header in addition to the
// files-api beta; without it the API returns 404.
func addManagedAgentsBetaForFiles(cmd *cli.Command, options []option.RequestOption) []option.RequestOption {
if cmd.IsSet("scope-id") {
if scopeID, ok := cmd.Value("scope-id").(string); ok && strings.HasPrefix(scopeID, "sesn_") {
return append(options, option.WithHeaderAdd("anthropic-beta", managedAgentsBeta))
}
}
return options
}

var betaFilesList = cli.Command{
Name: "list",
Usage: "List Files",
Expand Down Expand Up @@ -163,6 +179,7 @@ func handleBetaFilesList(ctx context.Context, cmd *cli.Command) error {
if err != nil {
return err
}
options = addManagedAgentsBetaForFiles(cmd, options)

params := anthropic.BetaFileListParams{}

Expand Down Expand Up @@ -276,6 +293,10 @@ func handleBetaFilesDownload(ctx context.Context, cmd *cli.Command) error {
if err != nil {
return err
}
// Download takes only a file ID, so we can't tell from flags whether the
// target is session-scoped. Send the managed-agents beta unconditionally;
// it is harmless on non-session files and required on session files.
options = append(options, option.WithHeaderAdd("anthropic-beta", managedAgentsBeta))

params := anthropic.BetaFileDownloadParams{}

Expand Down Expand Up @@ -316,6 +337,7 @@ func handleBetaFilesRetrieveMetadata(ctx context.Context, cmd *cli.Command) erro
if err != nil {
return err
}
options = append(options, option.WithHeaderAdd("anthropic-beta", managedAgentsBeta))

params := anthropic.BetaFileGetMetadataParams{}

Expand Down