# Directory layout (/workflows/code/directory)

`get` writes a directory, and every later command reads and rewrites it. Keep the `.sim/` folder: it is how Sim recognizes each block and resource again, and how an apply knows what version you read.

## Workflow directory \[#workflow-directory]

`sim workflows source get <workflowId> --dir <dir>` writes:

| Path | What it is | In git |
| - | - | - |
| `workflow.ts` | The workflow, in [file syntax](/workflows/code/syntax) | Commit |
| `functions/` | One file per Function block's code | Commit |
| `.sim/lock.json` | Ties each block in the file to the stored block, so renaming a block keeps its webhook URL, schedules and run history | Commit |
| `.sim/base.json` | The workflow ID and the version you read | Commit |
| `.sim/written.json` | A digest of each file as the CLI last wrote it, so `status` and `get` tell your edits from the CLI's | Commit |
| `.sim/stored-edges.json` | The connections the stored workflow held when it was printed, so an offline `check` tells them from connections you added. The CLI's own record, never sent | Commit |
| `.sim/starter.json` | The workspace a starter was written for, before `create` | Not kept: removed once the workflow exists |
| `.sim/AGENTS.md` | The guide for coding agents: the primer, then a reference | Optional, written again by `get` |
| `.sim/GUIDE-advanced.md` | The rest of the guide, by task: the edit loop step by step and what a dry run stubs, a new workflow or a fork, finding a builder and its types, the rules, and every diagnostic and exit code | Optional, written again by `get` |
| `.sim/examples/` | Example workflows to copy from | Optional, written again by `get` |
| `.sim/sdk/` | Type declarations for the blocks the workflow uses, and your workspace's tables, credentials, knowledge bases and environment variable names. `.sim/sdk/INDEX.md` lists the builders | Optional, written again by `get` and `check` |
| `tsconfig.json` | Resolves the declarations and type-checks the blocks the workflow uses. Left as it is if you already have one | Commit |
| `tsconfig.full.json` | Type-checks every block through the CLI's cache | Ignore: it names the cache on your machine, and `check` writes it again |
| `.gitattributes` | Keeps the source files on LF line endings | Commit |

The declarations of every block are generated once per block catalog into the CLI's cache, `~/.sim/cache/source-catalog/`, and shared by every directory. A workflow directory gets no `.gitignore`, so add the lines for what you ignore.

While a command runs it holds `.sim/command.lock/`, so two commands on one directory never interleave. A second one exits `10`.

## Workspace directory \[#workspace-directory]

`sim workspaces source get --dir <dir>` writes one folder per kind of resource. A kind is managed only when its folder or file exists.

```
secrets.ts                        the env variable names workflows read (never a value)
credentials.ts                    the saved credentials workflows use, by provider
tables/orders.ts                  a table: name, description, columns
tables/plans.rows.jsonl           a table's rows, one JSON object per line (only when the table opts in)
knowledge/policies/knowledge.ts   a knowledge base: name, chunking
knowledge/policies/docs/*.md      one file per document
files/templates/reply.md          a workspace file, at its folder path
tools/lookup-order.ts             a custom tool: title and schema
tools/lookup-order.js             the tool's code
skills/tone.md                    a skill: name and description, then its content
mcp/docs.ts                       an MCP server: url, headers
workflows/support/workflow.ts     a workflow directory
deployments/support.ts            how workflows/support is deployed
```

A resource's key is its file or folder name, and a workflow names it by that key. Every `.ts` file starts with the line `// @sim-sdk 1`, a deployment included; the one-line forms below show only the call. What each kind's file holds:

- `secrets.ts`: `export default defineSecrets({ NAME: { description? } })`, the workspace secrets workflows read, by name and description only (never a value: set one with `sim secrets set NAME --scope workspace`). A workflow: `env.NAME`; one using a declared secret the workspace has no value for is held back, and the rest apply.
- `credentials.ts`: `export default defineCredentials({ <key>: { provider, name? } })`, binding each key to this workspace's credential for that provider (never a token): the one bound already, else the only one, else the one whose display name is `name`. A workflow: `credential('<key>')`; one using a key no credential binds to is held back, and the rest apply.
- `tools/<key>.ts` (`defineTool({ title, schema, code: codeFile('./<key>.js') })`) and its code in `tools/<key>.js`, where each schema parameter is a variable. Code holding a literal credential prints as `code: stored()`, which keeps the stored code. A workflow: `customTool('<key>')`.
- `skills/<key>.md`: a frontmatter block of `name` and `description`, then the content. A workflow: `skills: [skill('<key>')]` on an agent.
- `mcp/<key>.ts`: `export default defineMcpServer({ name?, url, headers?, auth?, timeout?, retries?, enabled? })`. A credential header holds `env.NAME` or `'Bearer {{NAME}}'`, never a literal secret; `stored()` keeps the value the server holds. A new host or path in `url` replaces the server; a new query string updates it in place. A workflow: `mcp('<key>').tool('<name>')`.
- `tables/<key>.ts`: `export default defineTable({ name, description?, folder?, columns: { … } })` with `column.string()`, `column.number()`, `column.select({ options: [...] })`, … from `@sim/workflow-sdk/workspace`. Rows stay out of source unless `rows` opts in: `{ mode: 'managed', key: '<unique column>' }` keeps the rows equal to `tables/<key>.rows.jsonl` (one JSON object per line, keyed by column key), `{ mode: 'seed' }` writes them once into a new table. A workflow: `table('<key>')`.
- `knowledge/<key>/knowledge.ts` (`defineKnowledgeBase({ name, description?, folder?, chunking?, embeddingModel? })`) and `knowledge/<key>/docs/`, one file per document, flat. A workflow: `knowledgeBase('<key>')`. Connector-synced documents are never part of source.
- `files/<path>`: every file is one workspace file at that folder path; no declaration.
- `workflows/<key>/`: one workflow each, exactly a `sim workflows source get --dir` directory (`workflow.ts`, `functions/*`, `.sim/lock.json`, `.sim/base.json`).
- `deployments/<workflow key>.ts`: `defineDeployment({ live: 'draft' | 'pinned', api?: { public? }, chat? })` deploys `workflows/<workflow key>/`, so its schedule, webhook, API and chat triggers run. `live: 'draft'` publishes the draft whenever it differs from the live version; `'pinned'` never redeploys and says when the draft differs. A chat password is `env.NAME` (or `stored()` to keep the stored one); chat outputs name a block by its name. Removing the file undeploys the workflow (needs `--allow-delete`). Deploying needs workspace admin, never a workspace API key. MCP publishing is not part of source.

Beside the resources:

| Path | What it is | In git |
| - | - | - |
| `.sim/base.json` | The workspace the directory was read from and the version of every resource | Commit |
| `workflows/<key>/.sim/` | Each workflow's `lock.json`, `base.json` and `stored-edges.json`, as above | Commit |
| `.sim/written.json` | A digest of each file as the CLI last wrote it, so `status` and `get` tell your edits from the CLI's | Commit |
| `.sim/targets/<workspaceId>.json` | What each [promotion](/workflows/code/promote) left in that workspace | Commit |
| `.sim/skipped.json` | Documents and files a get left out, with the reason | Optional |
| `.sim/AGENTS.md`, `.sim/GUIDE-advanced.md`, `.sim/examples/`, `.sim/sdk/` | The agent guide with deletes, Git and CI, and promotion in depth; examples of every kind; type declarations including `.sim/sdk/workspace.d.ts` | Optional, written again by `get` |
| `.sim/cache/` | This machine's file stats. It ignores itself | Not committed |
| `tsconfig.json`, `tsconfig.full.json`, `.gitattributes`, `.gitignore` | As for a workflow directory. `.gitattributes` also keeps workspace files and knowledge base documents byte for byte | Commit all but `tsconfig.full.json` |

The generated `.gitignore` leaves out only what a command keeps while it runs (`.sim/downloads/`, `.sim/command.lock/`, `.sim-staging-*`) and `tsconfig.full.json`. Commit the rest, including `.sim/`: a fresh clone can then run `check`, `apply --dry` and `apply`.

## Related docs \[#related-docs]

- [Edit a workflow](/workflows/code/edit)
- [Manage a workspace as code](/workflows/code/workspace)
- [Run in CI](/workflows/code/ci)
- [Limits](/workflows/code/limits)
