Work with agents
Start an agent session
Your agent needs a token to work on a repository, and you do not want it to use yours. An agent session gives it a token of its own for one repository, which expires and never has more access than you.
3 min read
The forge records each action of the agent in the audit of the session.
You need src and the source skill on your computer. See Set up your coding agent.
1. Start a session
In a terminal, go to a checkout of the repository. Or add
-R <owner>/<repo>to the command.Start the session with a profile and a purpose:
src agent start --profile fixer --purpose "Fix issue 14" --ttl 3600Copy the token now.
srcprints it one time only, with the session id and the time that it expires.
Pick one of these profiles:
| Profile | What the agent can do |
|---|---|
reviewer (the default) | Read code, issues and pull requests, and comment. |
investigator | Read, comment and open issues. |
fixer | Push to its own branches, comment and open pull requests. |
--ttl is the token lifetime in seconds, at most 8 hours.
Tip
The MCP tool start_agent_session and the REST API start a session too.
2. Give the token to the agent
For Claude Code, add the MCP server of the forge with the session token. Connect over MCP has Cursor and other clients:
claude mcp add --transport http tanstack-source https://source.tanstack.com/mcp --header "Authorization: Bearer <session token>"
For git, the agent sends the token on each command:
git -c http.extraHeader="Authorization: Bearer $TANSTACK_SOURCE_TOKEN" clone https://source.tanstack.com/@<owner>/<repo>.git
git commit --trailer "Agent-Session: <session>" --trailer "On-Behalf-Of: <your user id>"
git -c http.extraHeader="Authorization: Bearer $TANSTACK_SOURCE_TOKEN" push origin HEAD:refs/heads/agent/<session>/<branch>
Important
Each commit that the agent pushes needs both trailers. If a commit has no trailers, the forge refuses the push, and the refusal names both trailers with their values.
The agent must send the token also on a public repository. Without the token, git reads the repository as anonymous, and the reads are not in the audit of the session.
3. Give the agent the context
Tell the agent to read this URL before it starts:
https://source.tanstack.com/@<owner>/<repo>/agents.md
It is one markdown file with:
- The
AGENTS.mdof the repository. - The instructions of its owner.
- The skills in the agent folders of the repository, such as
.agents/skillsand.claude/skills.
The URL of this file is always /@<owner>/<repo>/agents.md on the forge.
To give the agent the steps in one message, open the Code menu of the repository and click Copy prompt for your agent. The prompt tells the agent to clone the repository with src repo clone and then read this file.
Note
The skills of your profile or organization are not in the file. To give the agent a skill, add it to the repository first.
Done
Your agent works on one repository with its own token. To see each action that it did, run src agent audit <session>. See Check what your agent did.
What the agent can and cannot do
- It pushes only to
agent/<session>/...branches, or to the head branch of an open pull request when its token allows that. It never pushes to the default branch. - It can comment and review with the verdict "comment". It cannot approve a pull request or request changes.
- It never reads content that screening holds.
- To stop it, run
src agent revoke <session>. All tokens of the session stop at once, also in the middle of a push.
A session on a monorepo
A session on a monorepo also works on each of its members. On each member, the agent has your own role there, capped by its profile. It can open one monorepo pull request for its changes in all members, and a person merges it. See Give an agent a monorepo.