> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tokenfactory.nebius.com/llms.txt
> Use this file to discover all available pages before exploring further.

# file - Stage file edits for the next run

Stage file changes for the next `contree run`. Pending files are
automatically included without needing `--file` flags.

## Examples

```bash theme={null}
# Edit a file from the image in $EDITOR
contree file edit /etc/nginx/nginx.conf

# Stage a local file at a specific path
contree file cp ./config.yaml /etc/app/config.yaml

# Both edits apply on the next run
contree run nginx -t
```

## Help output

<div className="contree-terminal" style={{"border":"1px solid rgba(255,255,255,0.15)","borderRadius":8,"overflow":"hidden","margin":"1rem 0"}}><div style={{"background":"#292929","height":24,"display":"flex","alignItems":"center","padding":"0 12px","position":"relative"}}><div style={{"display":"flex","alignItems":"center","flexShrink":0}}><span style={{"display":"inline-block","width":10,"height":10,"borderRadius":"50%","background":"#ff5f57","marginRight":6}} /><span style={{"display":"inline-block","width":10,"height":10,"borderRadius":"50%","background":"#febc2e","marginRight":6}} /><span style={{"display":"inline-block","width":10,"height":10,"borderRadius":"50%","background":"#28c840"}} /></div><div style={{"position":"absolute","left":0,"right":0,"textAlign":"center","fontFamily":"-apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif","fontWeight":"bold","color":"#999"}}>\$ contree file --help</div></div><pre style={{"margin":0,"borderRadius":0,"padding":"8px 10px","background":"#1e1e1e","overflowX":"auto"}}><code style={{"fontFamily":"JetBrains Mono, SF Mono, SFMono-Regular, Menlo, Monaco, Cascadia Mono, Segoe UI Mono, Roboto Mono, Oxygen Mono, Ubuntu Monospace, Source Code Pro, Fira Mono, Droid Sans Mono, Consolas, Courier New, monospace","color":"#c5c8c6","whiteSpace":"pre-wrap"}}><span style={{"color":"#61afef","fontWeight":"bold"}}>usage: </span><span style={{"color":"#c678dd","fontWeight":"bold"}}>contree file</span><span style={{"color":"#c5c8c6"}}> \[</span><span style={{"color":"#98c379"}}>-h</span><span style={{"color":"#c5c8c6"}}>] </span><span style={{"color":"#98c379"}}>\{edit,e,cp,ls,list} ...</span><br /><br /><span style={{"color":"#c5c8c6"}}>Manage files in the session image.</span><br /><br /><span style={{"color":"#c5c8c6"}}>Subcommands:</span><br /><span style={{"color":"#c5c8c6"}}>  edit (e)  Download a file from the session image, open it in \$EDITOR</span><br /><span style={{"color":"#c5c8c6"}}>            (or vi), and upload the modified version as a pending file</span><br /><span style={{"color":"#c5c8c6"}}>            attachment. The change takes effect on the next \`run\`.</span><br /><br /><span style={{"color":"#c5c8c6"}}>  cp        Copy a local file into the session image as a pending file</span><br /><span style={{"color":"#c5c8c6"}}>            attachment. The file is uploaded immediately but injected</span><br /><span style={{"color":"#c5c8c6"}}>            into the sandbox on the next \`run\`.</span><br /><br /><span style={{"color":"#c5c8c6"}}>Pending files are branch-aware — switching branches changes which</span><br /><span style={{"color":"#c5c8c6"}}>files are visible.</span><br /><br /><span style={{"color":"#61afef","fontWeight":"bold"}}>positional arguments:</span><br /><span style={{"color":"#c5c8c6"}}>  </span><span style={{"color":"#98c379","fontWeight":"bold"}}>\{edit,e,cp,ls,list}</span><br /><span style={{"color":"#c5c8c6"}}>    </span><span style={{"color":"#98c379","fontWeight":"bold"}}>edit (e)</span><span style={{"color":"#c5c8c6"}}>           Edit a file in the session image</span><br /><span style={{"color":"#c5c8c6"}}>    </span><span style={{"color":"#98c379","fontWeight":"bold"}}>cp</span><span style={{"color":"#c5c8c6"}}>                 Copy a local file into the session image</span><br /><span style={{"color":"#c5c8c6"}}>    </span><span style={{"color":"#98c379","fontWeight":"bold"}}>ls (list)</span><span style={{"color":"#c5c8c6"}}>          List uploaded files (joined with local cache)</span><br /><br /><span style={{"color":"#61afef","fontWeight":"bold"}}>options:</span><br /><span style={{"color":"#c5c8c6"}}>  </span><span style={{"color":"#98c379","fontWeight":"bold"}}>-h</span><span style={{"color":"#c5c8c6"}}>, </span><span style={{"color":"#56b6c2","fontWeight":"bold"}}>--help</span><span style={{"color":"#c5c8c6"}}>           show this help message and exit</span><br /><br /><span style={{"color":"#c5c8c6"}}>for coding agents:</span><br /><span style={{"color":"#c5c8c6"}}>  mutating command (stages pending file changes for next run)</span><br /><span style={{"color":"#c5c8c6"}}>  file edit PATH uses local editor and uploads on change</span><br /><span style={{"color":"#c5c8c6"}}>  file cp SRC DEST uploads local file and stages DEST path</span><br /><br /><span style={{"color":"#c5c8c6"}}>agent note:</span><br /><span style={{"color":"#c5c8c6"}}>  Before using this command in an automated workflow, read:</span><br /><span style={{"color":"#c5c8c6"}}>    contree agent</span></code></pre></div>

## Subcommands

### `file edit`

`contree file edit PATH` (alias `e`) downloads the file at `PATH` from
the session image, opens it in `$EDITOR` (defaults to `vi`), and stages
the modified buffer as a pending upload that will be injected into the
next `contree run`. Missing files are created as empty buffers so the
command doubles as `touch + open`.

<div className="contree-terminal" style={{"border":"1px solid rgba(255,255,255,0.15)","borderRadius":8,"overflow":"hidden","margin":"1rem 0"}}><div style={{"background":"#292929","height":24,"display":"flex","alignItems":"center","padding":"0 12px","position":"relative"}}><div style={{"display":"flex","alignItems":"center","flexShrink":0}}><span style={{"display":"inline-block","width":10,"height":10,"borderRadius":"50%","background":"#ff5f57","marginRight":6}} /><span style={{"display":"inline-block","width":10,"height":10,"borderRadius":"50%","background":"#febc2e","marginRight":6}} /><span style={{"display":"inline-block","width":10,"height":10,"borderRadius":"50%","background":"#28c840"}} /></div><div style={{"position":"absolute","left":0,"right":0,"textAlign":"center","fontFamily":"-apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif","fontWeight":"bold","color":"#999"}}>\$ contree file edit --help</div></div><pre style={{"margin":0,"borderRadius":0,"padding":"8px 10px","background":"#1e1e1e","overflowX":"auto"}}><code style={{"fontFamily":"JetBrains Mono, SF Mono, SFMono-Regular, Menlo, Monaco, Cascadia Mono, Segoe UI Mono, Roboto Mono, Oxygen Mono, Ubuntu Monospace, Source Code Pro, Fira Mono, Droid Sans Mono, Consolas, Courier New, monospace","color":"#c5c8c6","whiteSpace":"pre-wrap"}}><span style={{"color":"#61afef","fontWeight":"bold"}}>usage: </span><span style={{"color":"#c678dd","fontWeight":"bold"}}>contree file edit</span><span style={{"color":"#c5c8c6"}}> \[</span><span style={{"color":"#98c379"}}>-h</span><span style={{"color":"#c5c8c6"}}>] \[</span><span style={{"color":"#98c379"}}>-E </span><span style={{"color":"#e5c07b"}}>EDITOR</span><span style={{"color":"#c5c8c6"}}>] </span><span style={{"color":"#98c379"}}>path</span><br /><br /><span style={{"color":"#c5c8c6"}}>Edit a remote file via a local editor. The updated content is uploaded and staged as a pending</span><br /><span style={{"color":"#c5c8c6"}}>file for the next run.</span><br /><br /><span style={{"color":"#61afef","fontWeight":"bold"}}>positional arguments:</span><br /><span style={{"color":"#c5c8c6"}}>  </span><span style={{"color":"#98c379","fontWeight":"bold"}}>path</span><span style={{"color":"#c5c8c6"}}>                 Path inside image</span><br /><br /><span style={{"color":"#61afef","fontWeight":"bold"}}>options:</span><br /><span style={{"color":"#c5c8c6"}}>  </span><span style={{"color":"#98c379","fontWeight":"bold"}}>-h</span><span style={{"color":"#c5c8c6"}}>, </span><span style={{"color":"#56b6c2","fontWeight":"bold"}}>--help</span><span style={{"color":"#c5c8c6"}}>           show this help message and exit</span><br /><span style={{"color":"#c5c8c6"}}>  </span><span style={{"color":"#98c379","fontWeight":"bold"}}>-E</span><span style={{"color":"#c5c8c6"}}>, </span><span style={{"color":"#56b6c2","fontWeight":"bold"}}>--editor</span><span style={{"color":"#c5c8c6"}}> </span><span style={{"color":"#e5c07b","fontWeight":"bold"}}>EDITOR</span><span style={{"color":"#c5c8c6"}}>  Editor command (default: /usr/bin/vim)</span><br /><br /><span style={{"color":"#c5c8c6"}}>for coding agents: mutates session state (adds pending file entry) does not apply immediately;</span><br /><span style={{"color":"#c5c8c6"}}>effect appears on next \`contree run\`</span></code></pre></div>

### `file cp`

`contree file cp SRC DEST` (alias `f`) reads a local file at `SRC`, uploads
it to the project’s file store, and stages it for delivery at `DEST` inside
the session image on the next `contree run`. Use this when you have a file
ready on disk locally and just want it materialised inside the sandbox
without spawning an instance first.

<div className="contree-terminal" style={{"border":"1px solid rgba(255,255,255,0.15)","borderRadius":8,"overflow":"hidden","margin":"1rem 0"}}><div style={{"background":"#292929","height":24,"display":"flex","alignItems":"center","padding":"0 12px","position":"relative"}}><div style={{"display":"flex","alignItems":"center","flexShrink":0}}><span style={{"display":"inline-block","width":10,"height":10,"borderRadius":"50%","background":"#ff5f57","marginRight":6}} /><span style={{"display":"inline-block","width":10,"height":10,"borderRadius":"50%","background":"#febc2e","marginRight":6}} /><span style={{"display":"inline-block","width":10,"height":10,"borderRadius":"50%","background":"#28c840"}} /></div><div style={{"position":"absolute","left":0,"right":0,"textAlign":"center","fontFamily":"-apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif","fontWeight":"bold","color":"#999"}}>\$ contree file cp --help</div></div><pre style={{"margin":0,"borderRadius":0,"padding":"8px 10px","background":"#1e1e1e","overflowX":"auto"}}><code style={{"fontFamily":"JetBrains Mono, SF Mono, SFMono-Regular, Menlo, Monaco, Cascadia Mono, Segoe UI Mono, Roboto Mono, Oxygen Mono, Ubuntu Monospace, Source Code Pro, Fira Mono, Droid Sans Mono, Consolas, Courier New, monospace","color":"#c5c8c6","whiteSpace":"pre-wrap"}}><span style={{"color":"#61afef","fontWeight":"bold"}}>usage: </span><span style={{"color":"#c678dd","fontWeight":"bold"}}>contree file cp</span><span style={{"color":"#c5c8c6"}}> \[</span><span style={{"color":"#98c379"}}>-h</span><span style={{"color":"#c5c8c6"}}>] </span><span style={{"color":"#98c379"}}>src</span><span style={{"color":"#c5c8c6"}}> </span><span style={{"color":"#98c379"}}>dest</span><br /><br /><span style={{"color":"#c5c8c6"}}>Upload a local file and stage it as a pending attachment to be injected on the next run.</span><br /><br /><span style={{"color":"#61afef","fontWeight":"bold"}}>positional arguments:</span><br /><span style={{"color":"#c5c8c6"}}>  </span><span style={{"color":"#98c379","fontWeight":"bold"}}>src</span><span style={{"color":"#c5c8c6"}}>         Local file path</span><br /><span style={{"color":"#c5c8c6"}}>  </span><span style={{"color":"#98c379","fontWeight":"bold"}}>dest</span><span style={{"color":"#c5c8c6"}}>        Destination path inside image</span><br /><br /><span style={{"color":"#61afef","fontWeight":"bold"}}>options:</span><br /><span style={{"color":"#c5c8c6"}}>  </span><span style={{"color":"#98c379","fontWeight":"bold"}}>-h</span><span style={{"color":"#c5c8c6"}}>, </span><span style={{"color":"#56b6c2","fontWeight":"bold"}}>--help</span><span style={{"color":"#c5c8c6"}}>  show this help message and exit</span><br /><br /><span style={{"color":"#c5c8c6"}}>for coding agents: mutates session state (adds pending file entry) destination path is inside</span><br /><span style={{"color":"#c5c8c6"}}>sandbox filesystem</span></code></pre></div>

### `file ls`

`contree file ls` lists files uploaded to the project (`GET /v1/files`)
and joins each row with the local upload cache. The `SOURCE` column shows
whatever this machine produced the file from:

* absolute host path for files uploaded via `run --file` or `COPY`;
* `https://...` URL for files fetched via `ADD URL`.

<Info>
  `SOURCE` resolves **only for files uploaded from this very machine**.
  The mapping lives in the local SQLite cache (per-profile, under
  `$CONTREE_HOME/cli/sessions/<profile>.db`) keyed by
  `path + inode + mtime + size` (host paths) or by the URL itself (URL
  fetches). It is **not** synced anywhere, so a row will show an empty
  `SOURCE` whenever:

  * the file was uploaded by a different machine, container, or teammate;
  * the file was uploaded by an earlier CLI version that did not yet
    track its origin (those entries backfill the next time the file is
    matched by the local cache);
  * the host file has been moved, renamed, or its `inode/mtime/size` has
    changed since upload (the cache key no longer matches and the
    mapping is treated as missing until the next upload).

  There is no way to recover the source of a file uploaded from another
  machine – the server stores only `uuid`, `sha256`, `size`,
  `created_at`, and `updated_at`.
</Info>

```bash theme={null}
contree file ls
contree file ls --since 1d --limit 200
contree file ls -q                # uuid + sha256 + source only
contree -f json file ls | jq 'select(.source != "")'
```

<div className="contree-terminal" style={{"border":"1px solid rgba(255,255,255,0.15)","borderRadius":8,"overflow":"hidden","margin":"1rem 0"}}><div style={{"background":"#292929","height":24,"display":"flex","alignItems":"center","padding":"0 12px","position":"relative"}}><div style={{"display":"flex","alignItems":"center","flexShrink":0}}><span style={{"display":"inline-block","width":10,"height":10,"borderRadius":"50%","background":"#ff5f57","marginRight":6}} /><span style={{"display":"inline-block","width":10,"height":10,"borderRadius":"50%","background":"#febc2e","marginRight":6}} /><span style={{"display":"inline-block","width":10,"height":10,"borderRadius":"50%","background":"#28c840"}} /></div><div style={{"position":"absolute","left":0,"right":0,"textAlign":"center","fontFamily":"-apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif","fontWeight":"bold","color":"#999"}}>\$ contree file ls --help</div></div><pre style={{"margin":0,"borderRadius":0,"padding":"8px 10px","background":"#1e1e1e","overflowX":"auto"}}><code style={{"fontFamily":"JetBrains Mono, SF Mono, SFMono-Regular, Menlo, Monaco, Cascadia Mono, Segoe UI Mono, Roboto Mono, Oxygen Mono, Ubuntu Monospace, Source Code Pro, Fira Mono, Droid Sans Mono, Consolas, Courier New, monospace","color":"#c5c8c6","whiteSpace":"pre-wrap"}}><span style={{"color":"#61afef","fontWeight":"bold"}}>usage: </span><span style={{"color":"#c678dd","fontWeight":"bold"}}>contree file ls</span><span style={{"color":"#c5c8c6"}}> \[</span><span style={{"color":"#98c379"}}>-h</span><span style={{"color":"#c5c8c6"}}>] \[</span><span style={{"color":"#56b6c2"}}>--since </span><span style={{"color":"#e5c07b"}}>SINCE</span><span style={{"color":"#c5c8c6"}}>] \[</span><span style={{"color":"#56b6c2"}}>--until </span><span style={{"color":"#e5c07b"}}>UNTIL</span><span style={{"color":"#c5c8c6"}}>] \[</span><span style={{"color":"#56b6c2"}}>--limit </span><span style={{"color":"#e5c07b"}}>LIMIT</span><span style={{"color":"#c5c8c6"}}>] \[</span><span style={{"color":"#98c379"}}>-q</span><span style={{"color":"#c5c8c6"}}>]</span><br /><br /><span style={{"color":"#c5c8c6"}}>List remote files uploaded to the project and, when present in the local upload cache, show what</span><br /><span style={{"color":"#c5c8c6"}}>produced them under the 'source' column: either an absolute host path (for run --file / COPY</span><br /><span style={{"color":"#c5c8c6"}}>uploads) or a URL (for ADD URL). source is THIS-MACHINE ONLY: the mapping lives in the local CLI</span><br /><span style={{"color":"#c5c8c6"}}>cache (\$CONTREE\_HOME/cli/sessions/\<profile>.db) and is never synced. Files uploaded from a</span><br /><span style={{"color":"#c5c8c6"}}>different host, by a teammate, or before tracking landed will show an empty source -- that is</span><br /><span style={{"color":"#c5c8c6"}}>expected, not a bug. Use the remote uuid or sha256 for cross-machine identity.</span><br /><br /><span style={{"color":"#61afef","fontWeight":"bold"}}>options:</span><br /><span style={{"color":"#c5c8c6"}}>  </span><span style={{"color":"#98c379","fontWeight":"bold"}}>-h</span><span style={{"color":"#c5c8c6"}}>, </span><span style={{"color":"#56b6c2","fontWeight":"bold"}}>--help</span><span style={{"color":"#c5c8c6"}}>     show this help message and exit</span><br /><span style={{"color":"#c5c8c6"}}>  </span><span style={{"color":"#56b6c2","fontWeight":"bold"}}>--since</span><span style={{"color":"#c5c8c6"}}> </span><span style={{"color":"#e5c07b","fontWeight":"bold"}}>SINCE</span><span style={{"color":"#c5c8c6"}}>  Parse +/- intervals (bare seconds or smhdMy) or ISO/date to UTC datetime.</span><br /><span style={{"color":"#c5c8c6"}}>  </span><span style={{"color":"#56b6c2","fontWeight":"bold"}}>--until</span><span style={{"color":"#c5c8c6"}}> </span><span style={{"color":"#e5c07b","fontWeight":"bold"}}>UNTIL</span><span style={{"color":"#c5c8c6"}}>  Show files before. Parse +/- intervals (bare seconds or smhdMy) or ISO/date to</span><br /><span style={{"color":"#c5c8c6"}}>                 UTC datetime.</span><br /><span style={{"color":"#c5c8c6"}}>  </span><span style={{"color":"#56b6c2","fontWeight":"bold"}}>--limit</span><span style={{"color":"#c5c8c6"}}> </span><span style={{"color":"#e5c07b","fontWeight":"bold"}}>LIMIT</span><span style={{"color":"#c5c8c6"}}>  Stop after this many files and warn if more are available</span><br /><span style={{"color":"#c5c8c6"}}>  </span><span style={{"color":"#98c379","fontWeight":"bold"}}>-q</span><span style={{"color":"#c5c8c6"}}>, </span><span style={{"color":"#56b6c2","fontWeight":"bold"}}>--quiet</span><span style={{"color":"#c5c8c6"}}>    Emit only uuid, sha256, and source columns. source is populated only for files</span><br /><span style={{"color":"#c5c8c6"}}>                 uploaded from this very machine.</span><br /><br /><span style={{"color":"#c5c8c6"}}>examples: contree file ls contree file ls --since 1d contree file ls --limit 5000 contree file ls</span><br /><span style={{"color":"#c5c8c6"}}>-q # uuid + sha256 + source contree -f json file ls</span></code></pre></div>

## Pending files

Pending files accumulate until the next `contree run` consumes them.
Explicit `--file` flags on `contree run` take priority over pending files
at the same path.

Files are uploaded with SHA256 dedup – identical content is not re-uploaded.

## See also

* [Working with Files](../tutorial/files) – full tutorial on file injection and editing
* [run - Execute a command in the sandbox](./run) – the `--file` syntax for inline file injection
