feat(auth): add td auth print-token for script and agent use#311
Open
scottlovegrove wants to merge 2 commits intomainfrom
Open
feat(auth): add td auth print-token for script and agent use#311scottlovegrove wants to merge 2 commits intomainfrom
td auth print-token for script and agent use#311scottlovegrove wants to merge 2 commits intomainfrom
Conversation
Prints the stored API token for the active user (or `--user <ref>`) to stdout so callers can capture it via `$(td auth print-token)` without exposing the token to an agent's conversation context. Refuses when `TODOIST_API_TOKEN` is set in the environment — the token is already available there, and silently echoing it would mask multi-user `--user` requests when env happens to be set. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
doistbot
reviewed
May 2, 2026
Member
doistbot
left a comment
There was a problem hiding this comment.
This PR introduces the td auth print-token subcommand to securely retrieve stored API tokens for scripts and agents, complete with thoughtful environment variable handling. The addition elegantly supports automation workflows without complicating the existing authentication commands. A few minor adjustments would polish this up, specifically updating the agent quick reference examples to use shell capture rather than bare invocations to prevent transcript token leaks, and ensuring the missing --user flag is included in the user mismatch test to align with its description.
- Skill content: replace bare `td auth print-token` examples with shell-capture form (`TOKEN=$(td auth print-token)`) so an agent following the quick reference literally can't leak the secret into its transcript. Strengthen the prose to call this out. - Tests: faithfully simulate `--user <ref>` in the UserNotFound propagation test by stubbing process.argv (where the global-args layer reads it from) and resetting the cache, mirroring how production wires `--user` around commander. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
td auth print-tokensubcommand prints the stored API token for the active user (or--user <ref>) to stdout, so scripts can capture it viaTOKEN=$(td auth print-token)without ever surfacing the token in an agent's conversation context.TODOIST_API_TOKENis set in the environment — the token is already available there, and silently echoing it would mask multi-user--userrequests when env happens to be set. New error codeTOKEN_FROM_ENVwith actionable hints.auth print-token(flat sibling) rather thanauth token viewto avoid colliding with the existingauth token [token]save command.Test plan
npm test -- src/commands/auth/auth.test.ts— 24/24 pass (4 new: happy path, env refusal,NoTokenErrorpropagation,UserNotFoundErrorpropagation)npm run check— lint + format cleannpm run check:skill-sync—skills/todoist-cli/SKILL.mdregenerated and in syncnpm run type-check— cleanTOKEN=$(td auth print-token); echo "len=${#TOKEN}"td auth print-token --user <other-email>resolves the right accountTODOIST_API_TOKEN=fake td auth print-tokenexits non-zero withTOKEN_FROM_ENV🤖 Generated with Claude Code