Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/ton-blockchain/acton/llms.txt

Use this file to discover all available pages before exploring further.

acton fmt is the opinionated Tolk code formatter built into Acton. It rewrites .tolk files in place to produce consistent, predictable output — uniform indentation, import ordering, and line width — so code review stays focused on logic rather than style. The formatter can also run in a non-destructive check mode for CI validation and accepts source from stdin for seamless editor integration.

Format all files in the project

Run without arguments from the project root to format every .tolk file discovered under it:
acton fmt
Acton scans the resolved project root recursively. Built-in directories (node_modules, .git, target, .acton, .codex, .claude) are always skipped.

Format selected files or directories

Pass one or more paths to limit the scope:
# Format all .tolk files under contracts/
acton fmt contracts

# Format a single file
acton fmt contracts/Counter.tolk

# Format multiple targets at once
acton fmt contracts scripts/deploy.tolk
This is especially useful in a pre-commit hook that formats only staged files.

Format from another directory

Point Acton at the project explicitly when the current shell is outside the project root:
acton fmt ../my-project
Use --manifest-path to also load a specific Acton.toml:
acton fmt --manifest-path ../my-project/Acton.toml ../my-project

Check mode (CI)

Use --check to validate formatting without rewriting files:
acton fmt --check
In check mode, Acton prints a diff for every file that does not match the formatter output and exits with a non-zero status. A zero exit status means all files are already formatted.
# Example CI step
acton fmt --check || (echo "Run acton fmt to fix formatting." && exit 1)

Stdin mode (editor integration)

Use --stdin to pipe source through the formatter without touching disk. This is the integration point used by editor plugins that format on save:
# Format and print to stdout
cat contracts/Counter.tolk | acton fmt --stdin

# Use --stdin-filepath to hint the display path in error messages
cat contracts/Counter.tolk | acton fmt --stdin --stdin-filepath contracts/Counter.tolk
--stdin cannot be combined with file or directory path arguments.

Diff output

--check already prints diffs for unformatted files. To see what changes acton fmt would make without applying them, combine --check with standard output redirection:
acton fmt --check 2>&1 | less

Configuring the formatter

Store formatter defaults in the [fmt] section of Acton.toml:
Acton.toml
[fmt]
width = 100
ignore = ["contracts/generated/*.tolk"]
separate-import-groups = true
FieldTypeDefaultDescription
widthinteger100Maximum formatted line width.
ignorestring[]Glob patterns of files to skip during recursive traversal.
separate-import-groupsbooleanfalseInsert a blank line between import groups.
Import groups are ordered as: @stdlib, @acton, @<other>, plain imports, ./, ../. The formatter sorts imports within each group automatically.
A file passed explicitly to acton fmt is still formatted even if it matches [fmt].ignore. Ignore patterns apply only during directory traversal, not to explicit path arguments.

Git pre-commit hook

Add a pre-commit hook to format staged Tolk files before every commit:
1
Create the hook file
2
cat > .git/hooks/pre-commit << 'EOF'
#!/usr/bin/env bash
set -e

# Collect staged .tolk files
STAGED=$(git diff --cached --name-only --diff-filter=ACMR | grep '\.tolk$' || true)
[ -z "$STAGED" ] && exit 0

# Format them in place
echo "$STAGED" | xargs acton fmt

# Re-stage the formatted files
echo "$STAGED" | xargs git add
EOF
chmod +x .git/hooks/pre-commit
3
Verify the hook works
4
Stage a .tolk file and run git commit. Acton formats the file before the commit is recorded.

Editor integration

The TON extension for VS Code calls acton fmt --stdin automatically on save. After installing the extension, add the following to your workspace settings.json:
.vscode/settings.json
{
  "[tolk]": {
    "editor.formatOnSave": true,
    "editor.defaultFormatter": "ton-core.vscode-ton"
  }
}
The extension reads [fmt] settings from Acton.toml automatically, so width and import-group preferences are respected without additional configuration.

Troubleshooting

Fix the parse error first, then run the formatter again. acton fmt formats only valid Tolk source files. The error output includes the file name and line where parsing failed.
Check whether the file path matches a pattern in [fmt].ignore or one of Acton’s built-in excluded directories: node_modules, .git, target, .acton, .codex, .claude. Pass the path explicitly to override ignore patterns.
Run acton fmt locally, commit the rewritten .tolk files, and rerun the pipeline. Make sure the same Acton.toml is checked in so the width and ignore settings match between local and CI environments.
Import ordering is deterministic. If order changes between runs, different versions of Acton may be producing different output. Pin the Acton version in [toolchain]:
Acton.toml
[toolchain]
acton = "0.1.0"

Build docs developers (and LLMs) love