Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

test(wrapper): verify subscription token forwarding

AkitaOnRails55af6d1473a5
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0683e783..5425a8d6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -43,7 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
the container boundary. The visible symptom is that the retry `status`
itself recommends — `llm-test --provider anthropic-oauth` — fails with a
missing-token error, because `llm-test` runs client-side in the helper
- rather than on the server ([#379]).
+ rather than on the server (#379).
## [1.24.0] - 2026-08-04
diff --git a/README.md b/README.md
index 6084795f..7aaf4aa2 100644
--- a/README.md
+++ b/README.md
@@ -880,7 +880,10 @@ lands in the same `ai-memory-data` volume as the server.
authenticates with an OAuth bearer token instead of an API key. Run
`claude setup-token` once, then set `AI_MEMORY_LLM_PROVIDER=anthropic-oauth` and
`ANTHROPIC_OAUTH_TOKEN=<token>` (or `CLAUDE_CODE_OAUTH_TOKEN`, which `claude
-setup-token` writes automatically). No `ANTHROPIC_API_KEY` is needed.
+setup-token` writes automatically). No `ANTHROPIC_API_KEY` is needed. The Docker
+wrappers forward either token by name to short-lived helper commands such as
+`llm-test`; configure the long-lived server container separately as shown in the
+installation guide.
**⚠️ Unofficial and against Anthropic's usage policies — use at your own risk;
it may get your account rate-limited or banned. See
[the warning in `docs/install.md`](docs/install.md#anthropic-via-claude-subscription-oauth).**
diff --git a/bin/ai-memory b/bin/ai-memory
index fb932323..dd36d621 100755
--- a/bin/ai-memory
+++ b/bin/ai-memory
@@ -22,6 +22,10 @@
# the wrapper reaches the host loopback server
# started by the README quick start.
# COPILOT_GITHUB_TOKEN GitHub token for AI_MEMORY_LLM_PROVIDER=copilot
+# ANTHROPIC_OAUTH_TOKEN Claude subscription token forwarded to helper
+# commands
+# CLAUDE_CODE_OAUTH_TOKEN fallback Claude subscription token forwarded
+# likewise
# AI_MEMORY_NO_TTY=1 force non-interactive even on a real tty
# AI_MEMORY_NO_VERSION_CHECK=1 skip the once-per-day update check
# AI_MEMORY_NATIVE_BIN native binary used for `run`/`show`/`continue` (optional)
diff --git a/crates/ai-memory-cli/tests/packaging.rs b/crates/ai-memory-cli/tests/packaging.rs
index 5bf091e0..dda9d47a 100644
--- a/crates/ai-memory-cli/tests/packaging.rs
+++ b/crates/ai-memory-cli/tests/packaging.rs
@@ -3,7 +3,7 @@
#[cfg(unix)]
use std::io::BufRead as _;
use std::path::{Path, PathBuf};
-#[cfg(unix)]
+#[cfg(any(unix, windows))]
use std::process::Command;
#[cfg(unix)]
use std::process::Stdio;
@@ -1028,9 +1028,19 @@ fn run_wrapper_with_fake_docker_and_claude_config(
None,
Some(claude_config_dir),
None,
+ &[],
)
}
+#[cfg(unix)]
+fn run_wrapper_with_fake_docker_and_forwarded_env(
+ args: &[&str],
+ docker_info_stdout: &str,
+ forwarded_env: &[(&str, &str)],
+) -> String {
+ run_wrapper_with_fake_docker_env(args, docker_info_stdout, None, None, None, forwarded_env)
+}
+
// The wrapper also shells out to `id -u` / `id -g` when choosing its default
// Docker uid mapping. Arch container tests often run as root, which would make
// the default mapping `-u 0:0` and produce a false positive in the assertions
@@ -1044,7 +1054,7 @@ fn run_wrapper_with_fake_docker_and_uname(
docker_info_stdout: &str,
uname_stdout: Option<&str>,
) -> String {
- run_wrapper_with_fake_docker_env(args, docker_info_stdout, uname_stdout, None, None)
+ run_wrapper_with_fake_docker_env(args, docker_info_stdout, uname_stdout, None, None, &[])
}
#[cfg(unix)]
@@ -1059,6 +1069,7 @@ fn run_wrapper_with_fake_selinux(
Some("Linux"),
None,
Some(selinux_mode),
+ &[],
)
}
@@ -1069,6 +1080,7 @@ fn run_wrapper_with_fake_docker_env(
uname_stdout: Option<&str>,
claude_config_dir: Option<&str>,
selinux_mode: Option<&str>,
+ forwarded_env: &[(&str, &str)],
) -> String {
let tmp = tempfile::tempdir().unwrap();
let docker_args = tmp.path().join("docker-args.txt");
@@ -1145,6 +1157,9 @@ fn run_wrapper_with_fake_docker_env(
if let Some(claude_config_dir) = claude_config_dir {
command.env("CLAUDE_CONFIG_DIR", claude_config_dir);
}
+ for (name, value) in forwarded_env {
+ command.env(name, value);
+ }
let output = command.output().unwrap();
assert!(
output.status.success(),
@@ -1305,21 +1320,95 @@ fn selinux_label_exception_requires_enforcement_and_daemon_support() {
);
}
+#[cfg(unix)]
#[test]
-fn wrapper_forwards_subscription_oauth_tokens_to_the_helper() {
- // `llm-test` runs client-side, inside the helper container, so the retry
- // that `status` itself suggests fails with a missing-token error unless
- // the subscription tokens reach it. The API-key variables were already
- // forwarded; their OAuth counterparts were not. Both wrappers keep their
- // own hand-maintained list, and both had the same hole.
- for wrapper_path in ["bin/ai-memory", "bin/ai-memory.ps1"] {
- let wrapper = read_repo(wrapper_path);
- for var in ["ANTHROPIC_OAUTH_TOKEN", "CLAUDE_CODE_OAUTH_TOKEN"] {
- assert!(
- wrapper.contains(var),
- "{wrapper_path} must forward {var} to the helper container"
- );
- }
+fn posix_wrapper_forwards_subscription_oauth_tokens_without_putting_values_in_argv() {
+ let tokens = [
+ ("ANTHROPIC_OAUTH_TOKEN", "oauth-canary-primary"),
+ ("CLAUDE_CODE_OAUTH_TOKEN", "oauth-canary-fallback"),
+ ];
+ let args = run_wrapper_with_fake_docker_and_forwarded_env(
+ &["llm-test", "--provider", "anthropic-oauth"],
+ "[name=seccomp,profile=default]",
+ &tokens,
+ );
+ let args: Vec<&str> = args.lines().collect();
+
+ for (name, value) in tokens {
+ assert!(
+ args.windows(2).any(|pair| pair == ["-e", name]),
+ "wrapper must forward {name} by name; got {args:?}"
+ );
+ assert!(
+ !args.iter().any(|arg| arg.contains(value)),
+ "wrapper must not put the value of {name} in Docker argv"
+ );
+ }
+}
+
+#[test]
+fn powershell_wrapper_lists_subscription_oauth_tokens_in_its_env_allowlist() {
+ let wrapper = read_repo("bin/ai-memory.ps1");
+ let allowlist = wrapper
+ .split_once("foreach ($Name in @(")
+ .and_then(|(_, rest)| rest.split_once(")) {"))
+ .map(|(allowlist, _)| allowlist)
+ .expect("PowerShell wrapper env allowlist");
+
+ for name in ["ANTHROPIC_OAUTH_TOKEN", "CLAUDE_CODE_OAUTH_TOKEN"] {
+ assert!(
+ allowlist
+ .lines()
+ .any(|line| line.trim() == format!("\"{name}\",")),
+ "PowerShell wrapper must list {name} in the helper env allowlist"
+ );
+ }
+}
+
+#[cfg(windows)]
+#[test]
+fn powershell_wrapper_forwards_subscription_oauth_tokens_without_putting_values_in_argv() {
+ let tmp = tempfile::tempdir().unwrap();
+ let docker_args = tmp.path().join("docker-args.txt");
+ let docker = tmp.path().join("docker.cmd");
+ std::fs::write(
+ &docker,
+ "@echo off\r\n>\"%AI_MEMORY_TEST_DOCKER_ARGS%\" echo %*\r\nexit /b 0\r\n",
+ )
+ .unwrap();
+
+ let tokens = [
+ ("ANTHROPIC_OAUTH_TOKEN", "oauth-canary-primary"),
+ ("CLAUDE_CODE_OAUTH_TOKEN", "oauth-canary-fallback"),
+ ];
+ let mut command = Command::new("powershell.exe");
+ command
+ .args(["-NoLogo", "-NoProfile", "-NonInteractive", "-File"])
+ .arg(repo_root().join("bin/ai-memory.ps1"))
+ .args(["llm-test", "--provider", "anthropic-oauth"])
+ .env("AI_MEMORY_DOCKER", &docker)
+ .env("AI_MEMORY_TEST_DOCKER_ARGS", &docker_args);
+ for (name, value) in tokens {
+ command.env(name, value);
+ }
+ let output = command.output().unwrap();
+ assert!(
+ output.status.success(),
+ "PowerShell wrapper failed: stdout={} stderr={}",
+ String::from_utf8_lossy(&output.stdout),
+ String::from_utf8_lossy(&output.stderr)
+ );
+
+ let args = std::fs::read_to_string(docker_args).unwrap();
+ for (name, value) in tokens {
+ assert!(
+ args.contains(&format!("-e {name}")),
+ "PowerShell wrapper must forward {name} by name; got {args}"
+ );
+ assert!(
+ !args.contains(value),
+ "PowerShell wrapper must not put the value of {name} in Docker argv"
+ );
}
}
diff --git a/docs/install.md b/docs/install.md
index fd565cf3..a3a25fc2 100644
--- a/docs/install.md
+++ b/docs/install.md
@@ -1247,7 +1247,12 @@ docker run -d --name ai-memory \
```
Both `ANTHROPIC_OAUTH_TOKEN` and `CLAUDE_CODE_OAUTH_TOKEN` are accepted;
-ai-memory checks `ANTHROPIC_OAUTH_TOKEN` first.
+ai-memory checks `ANTHROPIC_OAUTH_TOKEN` first. When either variable is exported
+on the host, the POSIX and PowerShell Docker wrappers forward its name to
+short-lived helper commands such as `llm-test`; the token value is inherited by
+Docker rather than placed in the wrapper's command line. The long-lived server
+container still needs the provider and token variables in its own environment,
+as in the example above.
> [!TIP]
> **Pick a small, fast model.** ai-memory's LLM work — session